{"action":"closed","issue":{"url":"https://api.github.com/repos/Azure/azure-storage-net/issues/465","repository_url":"https://api.github.com/repos/Azure/azure-storage-net","labels_url":"https://api.github.com/repos/Azure/azure-storage-net/issues/465/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-storage-net/issues/465/comments","events_url":"https://api.github.com/repos/Azure/azure-storage-net/issues/465/events","html_url":"https://github.com/Azure/azure-storage-net/issues/465","id":231931790,"number":465,"title":"Azure Storage is still hard to unit test / mock","user":{"login":"PureKrome","id":899878,"avatar_url":"https://avatars1.githubusercontent.com/u/899878?v=4","gravatar_id":"","url":"https://api.github.com/users/PureKrome","html_url":"https://github.com/PureKrome","followers_url":"https://api.github.com/users/PureKrome/followers","following_url":"https://api.github.com/users/PureKrome/following{/other_user}","gists_url":"https://api.github.com/users/PureKrome/gists{/gist_id}","starred_url":"https://api.github.com/users/PureKrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PureKrome/subscriptions","organizations_url":"https://api.github.com/users/PureKrome/orgs","repos_url":"https://api.github.com/users/PureKrome/repos","events_url":"https://api.github.com/users/PureKrome/events{/privacy}","received_events_url":"https://api.github.com/users/PureKrome/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"erezvani1529","id":7978554,"avatar_url":"https://avatars2.githubusercontent.com/u/7978554?v=4","gravatar_id":"","url":"https://api.github.com/users/erezvani1529","html_url":"https://github.com/erezvani1529","followers_url":"https://api.github.com/users/erezvani1529/followers","following_url":"https://api.github.com/users/erezvani1529/following{/other_user}","gists_url":"https://api.github.com/users/erezvani1529/gists{/gist_id}","starred_url":"https://api.github.com/users/erezvani1529/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erezvani1529/subscriptions","organizations_url":"https://api.github.com/users/erezvani1529/orgs","repos_url":"https://api.github.com/users/erezvani1529/repos","events_url":"https://api.github.com/users/erezvani1529/events{/privacy}","received_events_url":"https://api.github.com/users/erezvani1529/received_events","type":"User","site_admin":false},"assignees":[{"login":"erezvani1529","id":7978554,"avatar_url":"https://avatars2.githubusercontent.com/u/7978554?v=4","gravatar_id":"","url":"https://api.github.com/users/erezvani1529","html_url":"https://github.com/erezvani1529","followers_url":"https://api.github.com/users/erezvani1529/followers","following_url":"https://api.github.com/users/erezvani1529/following{/other_user}","gists_url":"https://api.github.com/users/erezvani1529/gists{/gist_id}","starred_url":"https://api.github.com/users/erezvani1529/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erezvani1529/subscriptions","organizations_url":"https://api.github.com/users/erezvani1529/orgs","repos_url":"https://api.github.com/users/erezvani1529/repos","events_url":"https://api.github.com/users/erezvani1529/events{/privacy}","received_events_url":"https://api.github.com/users/erezvani1529/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/Azure/azure-storage-net/milestones/2","html_url":"https://github.com/Azure/azure-storage-net/milestone/2","labels_url":"https://api.github.com/repos/Azure/azure-storage-net/milestones/2/labels","id":2259144,"number":2,"title":"9.0","description":"Major version release 9.0.","creator":{"login":"erezvani1529","id":7978554,"avatar_url":"https://avatars2.githubusercontent.com/u/7978554?v=4","gravatar_id":"","url":"https://api.github.com/users/erezvani1529","html_url":"https://github.com/erezvani1529","followers_url":"https://api.github.com/users/erezvani1529/followers","following_url":"https://api.github.com/users/erezvani1529/following{/other_user}","gists_url":"https://api.github.com/users/erezvani1529/gists{/gist_id}","starred_url":"https://api.github.com/users/erezvani1529/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erezvani1529/subscriptions","organizations_url":"https://api.github.com/users/erezvani1529/orgs","repos_url":"https://api.github.com/users/erezvani1529/repos","events_url":"https://api.github.com/users/erezvani1529/events{/privacy}","received_events_url":"https://api.github.com/users/erezvani1529/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":4,"state":"open","created_at":"2017-01-17T17:30:04Z","updated_at":"2018-02-07T22:22:44Z","due_on":"2018-01-15T08:00:00Z","closed_at":null},"comments":15,"created_at":"2017-05-29T05:45:47Z","updated_at":"2018-02-07T22:22:44Z","closed_at":"2018-02-07T22:22:44Z","author_association":"NONE","body":"Hi Azure Storage team!\r\n\r\n(question editted with extra info, about 10 mins after posting this).\r\n\r\nThis question is a continuation of #349, #318 and sorta #80 \r\n\r\nWith release version `8.*` of the Azure SDK more methods have been `virtualized`. Yay! better unit testing :)\r\n\r\nBut ... I'm not having much luck with some stuff still -> mainly when I need to access a property .. which relys on some internal magic ... like the `Name` of a `CloudFile` or `CloudDirectory`, etc. This is because the `constructors` require specific arguments passed in (I believe).\r\n\r\n**I think we might need some more things `virtualized`** => I think `sss` needs to be virtualized.\r\n\r\nSo .. given the latest `8.*` version of the SDK, how could this simple piece of code be Unit Tested?\r\n\r\nHere is the code I wish to test: Given a `Share` in my Azure File Storage, list all the folders that exist in that share.\r\n\r\nHere's my code which I believe does this...\r\n\r\n```\r\npublic class AzureFileServiceExample\r\n{\r\n    private readonly CloudFileClient _cloudFileClient;\r\n\r\n    public AzureFileServiceExample(CloudFileClient cloudFileClient)\r\n    {\r\n        _cloudFileClient = cloudFileClient;\r\n    }\r\n\r\n    public string[] GetDirectories()\r\n    {\r\n        // 1. Get a reference to the main, root share directory in yout azure storage account.\r\n        var shareRootDirectory = _cloudFileClient.GetShareReference(\"ShareDirectoryInAzure\")\r\n                                                 .GetRootDirectoryReference();\r\n\r\n        // 2. Get a list of all the directories in this share.\r\n        var directories = shareRootDirectory.ListFilesAndDirectories()\r\n                                            .OfType<CloudFileDirectory>()\r\n                                            .Select(x => x.Name)\r\n                                            .ToArray();\r\n\r\n        return directories;\r\n    }\r\n}\r\n```\r\n\r\n---\r\n\r\nHere's a start of some unit testing code to help kick start things to make your life easier :\r\n```\r\n[Fact]\r\npublic void GivenSomeFilesExist_GetDirectories_ReturnsSomeDirectoryNames()\r\n{\r\n    // Arrange.\r\n    const string uri = \"https://pewpew.file.core.windows.net/\";\r\n\r\n    var fakeStorageUri = new StorageUri(new Uri($\"{uri}movies/\"));\r\n    var fakeStorageCredentials = new StorageCredentials();\r\n\r\n    var existingFilesAndDirectories = new IListFileItem[]\r\n    {\r\n        new CloudFileDirectory(new StorageUri(new Uri($\"{uri}movies/folder-a/\")), fakeStorageCredentials),\r\n        new CloudFileDirectory(new StorageUri(new Uri($\"{uri}movies/folder-b/\")), fakeStorageCredentials),\r\n        new CloudFile(new StorageUri(new Uri($\"{uri}movies/folder-a/file-a.xml\")), fakeStorageCredentials),\r\n        new CloudFile(new StorageUri(new Uri($\"{uri}movies/folder-a/file-b.json\")), fakeStorageCredentials),\r\n        new CloudFile(new StorageUri(new Uri($\"{uri}movies/folder-a/file-c.zip\")), fakeStorageCredentials),\r\n        new CloudFile(new StorageUri(new Uri($\"{uri}movies/folder-b/file-1.xml\")), fakeStorageCredentials),\r\n        new CloudFile(new StorageUri(new Uri($\"{uri}movies/folder-b/file-2.json\")), fakeStorageCredentials)\r\n    };\r\n\r\n    var cloudFileDirectory = new Mock<CloudFileDirectory>(fakeStorageUri, fakeStorageCredentials);\r\n    cloudFileDirectory.Setup(x => x.ListFilesAndDirectories(null, null))\r\n                        .Returns(existingFilesAndDirectories);\r\n\r\n    var cloudFileShare = new Mock<CloudFileShare>(fakeStorageUri, fakeStorageCredentials);\r\n    // cloudFileShare.Setup(x => x.GetRootDirectoryReference())\r\n    //               .Returns(cloudFileDirectory.Object);  // <-- Cannot work cause it's not virtual.\r\n\r\n    var cloudFileClient = new Mock<CloudFileClient>(fakeStorageUri, fakeStorageCredentials);\r\n    cloudFileClient.Setup(x => x.GetShareReference(UniqueKeys.AzureFileShareDirectoryKey))\r\n                    .Returns(cloudFileShare.Object);\r\n\r\n    var fileService = new AzureFileServiceExample(cloudFileClient.Object);\r\n\r\n    // Act.\r\n    var files = fileService.GetDirectories();\r\n\r\n    // Assert.\r\n   // lots of checks and verifies here.\r\n}\r\n```\r\n\r\nProblem: Because we cannot mock the `GetRootDirectoryReference()` method, a real `CloudFileDirectory` instance is returned. Which means it will do _real_ hits to the storage endpoints. Not kewl 😢 \r\n\r\n**So - could we please add `virtual` to `GetRootDirectoryReference()` please?**\r\n\r\nSide Point: would also love the properties also made virtual also 👍 Like `Name` etc...\r\n\r\nNOTE: I know this feels like a StackOverflow question, but I wanted to ask here because I'm really asking if the SDK has been designed enough to handle unit testing. Also, please do not suggest using the emulator in a unit testing (manual/local, CI/CD scenario's) situation please."}}
{"actor":{"display_login":"erezvani1529"}}