public async void CreateDirectory_Ok() { // Mock apis var readApiMock = new Mock <IReadApi>(); var writeApiMock = new Mock <IWriteApi>(); // Setup dummy response var directoryMetadataMock = new Mock <IDirectoryMetadata>(); directoryMetadataMock.SetupGet(x => x.ObjectId).Returns("MyDirectoryId"); directoryMetadataMock.SetupGet(x => x.SizeInBytes).Returns((uint)myFile.Length); directoryMetadataMock.SetupGet(x => x.ObjectName).Returns("MyDirectory"); directoryMetadataMock.SetupGet(x => x.FileChilds).Returns(new IFileMetadata[0]); directoryMetadataMock.SetupGet(x => x.DirectoryChilds).Returns(new IMinimalDirectoryMetadata[0]); directoryMetadataMock.SetupGet(x => x.LatestViewDate).Returns(DateTime.MaxValue); directoryMetadataMock.SetupGet(x => x.LatestChangeDate).Returns(DateTime.MinValue); directoryMetadataMock.SetupGet(x => x.NumberOfChilds).Returns(1); var directoryMetadataMockObject = directoryMetadataMock.Object; writeApiMock.Setup(mock => mock.ObjectApi.CreateDirectory( It.IsAny <string>(), It.IsAny <string>() )).ReturnsAsync(directoryMetadataMockObject); var controller = new ObjectController(AppSettings, writeApiMock.Object, readApiMock.Object); var response = await controller.CreateDirectory("Test", new CreateDirectoryRequest() { SubDirectoryName = "SubTest" }); var responseObject = Assert.IsType <OkObjectResult>(response); var directoryMetadata = Assert.IsAssignableFrom <IDirectoryMetadata>(responseObject.Value); Assert.Equal(directoryMetadataMockObject.ObjectId, directoryMetadata.ObjectId); Assert.Equal(directoryMetadataMockObject.SizeInBytes, directoryMetadata.SizeInBytes); Assert.Equal(directoryMetadataMockObject.ObjectName, directoryMetadata.ObjectName); Assert.Equal(directoryMetadataMockObject.FileChilds, directoryMetadata.FileChilds); Assert.Equal(directoryMetadataMockObject.DirectoryChilds, directoryMetadata.DirectoryChilds); Assert.Equal(directoryMetadataMockObject.LatestChangeDate, directoryMetadata.LatestChangeDate); Assert.Equal(directoryMetadataMockObject.LatestViewDate, directoryMetadata.LatestViewDate); Assert.Equal(directoryMetadataMockObject.NumberOfChilds, directoryMetadata.NumberOfChilds); }
public async void CreateDirectory_Throws() { // Mock apis var readApiMock = new Mock <IReadApi>(); var writeApiMock = new Mock <IWriteApi>(); writeApiMock.Setup(mock => mock.ObjectApi.CreateDirectory( It.IsAny <string>(), It.IsAny <string>() )).Throws <InvalidOperationException>(); var controller = new ObjectController(AppSettings, writeApiMock.Object, readApiMock.Object); var response = await controller.CreateDirectory("Test", new CreateDirectoryRequest() { SubDirectoryName = "SubTest" }); Assert.IsType <BadRequestResult>(response); }