Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUERY] Is it possible to set LastModified property from BlobContainerProperties? #20091

Closed
WillRock19 opened this issue Apr 5, 2021 · 9 comments
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@WillRock19
Copy link

WillRock19 commented Apr 5, 2021

Query/Question

I want to unit test a logic in my code. The logic gets a BlobContainerClient from the storage, get all blobs from it, and then filter the blobs for those who last modified date is before last week and delete those. I have somethind as the following:

                var blobContainerClient = storageWrapper.GetContainerReference(_connectionString, containerName); //returns a BlobContainerClient
                var dateLastWeek = DateTime.Now.AddDays(-7);

                var desiredBlobs = blobContainerClient
                    .GetBlobs()
                    .ToList()
                    .Where(x => x.Properties.LastModified < dateLastWeek)
                    .ToList();

But then I realized that the BlobContainerProperties.LastModified is a get only property, and non virtual (so I can't mock it's return).

image

Is there a way to create one of these objects with the LastModified date so I can use it in my test logic?

Environment:

  • .Net Version: Full Framework 4.8
  • New version: Azure.Storage.Blobs v12.8.0
  • IDE and version : Visual Studio 16.8.5
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 5, 2021
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels Apr 5, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Apr 5, 2021
@ghost
Copy link

ghost commented Apr 5, 2021

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

Issue Details

Query/Question

I want to unit test a logic in my code. The logic gets a BlobContainerClient from the storage, get all blobs from it, and then filter the blobs for those who last modified date is before last week and delete those. I have somethind as the following:

                var blobContainerClient = storageWrapper.GetContainerReference(_connectionString, containerName); //returns a BlobContainerClient
                var dateLastWeek = DateTime.Now.AddDays(-7);

                var desiredBlobs = blobContainerClient
                    .GetBlobs()
                    .ToList()
                    .Where(x => x.Properties.LastModified < dateLastWeek)
                    .ToList();

But then I realized that the BlobContainerProperties.LastModified is a get only property, and not virtual. Is there a way to fake it so I can test my logic?

Environment:

  • .Net Version: Full Framework 4.8
  • New version: Azure.Storage.Blobs v12.8.0
  • IDE and version : Visual Studio 16.8.5
Author: WillRock19
Assignees: -
Labels:

Client, Service Attention, Storage, customer-reported, needs-team-attention, needs-triage, question

Milestone: -

@seanmcc-msft
Copy link
Member

Hi @WillRock19,

To create a BlobContainerProperties for testing purposes, I recommend using BlobsModelFactory.BlobContainerProperties()

You can then create a mock BlobContainerClient, and set it up to return the BlobContainerProperties in question. BlobContainerClient.GetProperties() and BlobContainerClient.GetPropertiesAsync() are virtual.

-Sean

@seanmcc-msft
Copy link
Member

You can create a BlobItemProperties for testing with BlobsModelFactory.BlobItem(). You can create the BlobItemProperties with BlobsModelFactory.BlobItemProperties().

@WillRock19
Copy link
Author

WillRock19 commented Apr 5, 2021

@seanmcc-msft thanks for the answers! I'm sorry to say I've tried to remove the question from this topic and created a new one, so it could be easily found by people that may strougle with the same issue. I'm not able to delete the other topic (here it is: #20124), and I'm sorry about the confusion.

@WillRock19
Copy link
Author

@seanmcc-msft, I've tried your sugestion, but the Azure.Core.PageResponseEnumerator is internal. Is that right?

@seanmcc-msft
Copy link
Member

@tg-msft

@tg-msft
Copy link
Member

tg-msft commented Apr 5, 2021

https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Mocking.md#creating-a-mock-of-the-method-that-returns-pageable has an example of mocking Pageable<T>.

@WillRock19
Copy link
Author

It worked! Thank you very much :)

azure-sdk pushed a commit to azure-sdk/azure-sdk-for-net that referenced this issue Sep 19, 2022
Network 2022 05 01 (Azure#20695)

* Adds base for updating Microsoft.Network from version stable/2022-01-01 to version 2022-05-01

* Updates readme

* Updates API version in new specs and examples

* add DisableTcpStateTracking on nic (Azure#19734)

Co-authored-by: Dan Tu <dantu@microsoft.com>

* Adding new VIP Swap APIs to support extension resource design (Azure#19698)

* Adding new VIP Swap APIs to support extension resource design

* fixing validation checks

* minor fix

* Reverting changes

* Minor fix to add a new line

* fix description (Azure#19987)

Co-authored-by: Dan Tu <dantu@microsoft.com>

* Add BillingType Property to ExpressRoutePorts (Azure#19932)

* change port json

* changes

* add Virtual network gateway policy group api (Azure#19766)

* finish update on connection configuration references

* resolve reference error

* finish prettier

* resolve sematic error

* finish update change

* enablePrivateLinkFastPath property for VirtualNetworkGatewayConnection resource (Azure#20050)

* Support for Per Rule Actions in Application Gateway WAF (Azure#20027)

* Adding changes for per rule actions

* Fixing spaces

* prettier fix

* Addressing PR comments

* Address review comments

* Add ColoLocation to ExpressRoutePort result (Azure#20033)

* Add ColoLocation to ExpressRoutePort result

* Fix automation code check error

* Merge from network-2022-05-01

* Revert "Merge from network-2022-05-01"

This reverts commit f0671a040b2bad684921f8f8ad4b53bb0f4b4a93.

Co-authored-by: Jianqi Zhao <jianzhao@microsoft.com>

* DDoS Per IP SKU + Custom Policy Deprecation Swagger PR (Azure#19985)

* initial changes

* example file changes

* new files for new apis

* adding a period

* changing reference

* prettier fixes

* ddos fix

* lint diff fixes

* more lint diff errors

* fixing operation id

* changing bool to string enum

* example changes

* adding 202s as these are long running ops

* examples

Co-authored-by: Manas Chakka <manaschakka@microsoft.com>

* Adding UnhealthyThreshold property to LB health probes, and updated examples with new property (Azure#20001)

* Property to enable/disable OCSP revocation check on client certificate (Azure#20301)

* add new property to enable/disable OCSP revocation check on client certificate for MTLS

* revert breaking change of updating enum property

* Add new parameter asn, geo and expressRouteAdvertise to CustomIPPrefix for new 2022-05-01 nrp sdk version (Azure#20266)

* fix

* fix

* fix

* fix

* fix

* fix

Co-authored-by: Weiheng Li <weihl@microsoft.com>

* Network 2022-05-01 Azure Virtual Network Manager Contributions (Azure#20440)

* Add third NIP enum for avnm security admin config, AllowRulesOnly

* add optional top parameters to various network manager post APIs

* revise all example input subscriptions to all zero guid

* change all top parameter max value to 100

* Revert "change all top parameter max value to 100"

This reverts commit 12943d2f2b91b22f1dae232cb291a8551fedfdca.

Co-authored-by: Jared Gorthy <jaredgorthy@microsoft.com>

* Alpelled waf manifest 05 01 2022 (Azure#20047)

* init

* init

* fix comments

* fix err

* try ref to appgw def

* try ref to appgw def

* try ref to appgw def

* try ref to appgw def

* update example

* update example

* update example

* update state and action

* update state and action

* change ruleset name and add tiers

* cammel case fix

* cammel case fix

* s_ruleid

* s_RuleId

* suppress s_RuleId camel case issue

* suppress s_RuleId camel case issue

* address comments

* address comments

* address comments

* fix typo

* cont fix

* cont fix

* cont fix

* cont fix

* cont fix

* add pageable

* add next link

Co-authored-by: Alon Pelled <alpelled@microsoft.com>

* Add prefixType property to CustomIPPrefix for NRP 2022-05-01 (Azure#20486)

* add prefixType parameter

* add example

* Adding swagger changes for routemaps feature (Azure#20091)

* initial changes for routemaps

* run npm prettier script

* adding examples

* fixing validation errors

* more validations

* more fixes

* trying to fix lint error

* fix for match condition

* renaming ActionType to fix lint

* fix for python sdk generation

* renaming Rule to RouteMapRule

* modify examples to remove vnetroutes from non hub vnet conns

* cleanup

* Added Upper-case transform (Azure#20674)

Co-authored-by: dtuCloud <tudan0103@gmail.com>
Co-authored-by: Dan Tu <dantu@microsoft.com>
Co-authored-by: shnaya434 <67019054+shnaya434@users.noreply.github.com>
Co-authored-by: nimaller <71352534+nimaller@users.noreply.github.com>
Co-authored-by: tyrannicrex <jiaczh@microsoft.com>
Co-authored-by: Jesus Arango <jearango@microsoft.com>
Co-authored-by: Sindhu Aluguvelli <sindhureddy216@gmail.com>
Co-authored-by: Jianqi Zhao <archie.j.zhao@gmail.com>
Co-authored-by: Jianqi Zhao <jianzhao@microsoft.com>
Co-authored-by: Manas Chakka <mchakka@gmail.com>
Co-authored-by: Manas Chakka <manaschakka@microsoft.com>
Co-authored-by: bhavanabheem <109241669+bhavanabheem@users.noreply.github.com>
Co-authored-by: biaogao <biga@microsoft.com>
Co-authored-by: Weiheng Li <weihengli.tj@gmail.com>
Co-authored-by: Weiheng Li <weihl@microsoft.com>
Co-authored-by: jago2136 <42753636+jago2136@users.noreply.github.com>
Co-authored-by: Jared Gorthy <jaredgorthy@microsoft.com>
Co-authored-by: alon-microsoft <31221093+alon-microsoft@users.noreply.github.com>
Co-authored-by: Alon Pelled <alpelled@microsoft.com>
Co-authored-by: Eric Hoffmann <112216215+erichoffmannms@users.noreply.github.com>
Co-authored-by: arganapathy <109313670+arganapathy@users.noreply.github.com>
Co-authored-by: rahulbissa2727 <106511944+rahulbissa2727@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

4 participants