public async Task TestGetVolume() { VolumeReply volumeReply = new VolumeReply() { Id = "vol-0000000", Name = "TestVolumeName", SizeGb = 3 }; volumeReply.MountPoints.Add("c:"); Mock <IDatabase> databaseMock = new Mock <IDatabase>(); databaseMock.Setup(d => d.KeyExists(It.IsAny <RedisKey>(), CommandFlags.None)).Returns(true); databaseMock.Setup(d => d.HashGetAsync(It.IsAny <RedisKey>(), It.IsAny <RedisValue>(), CommandFlags.None)) .Returns(async(RedisKey userId, RedisValue key, CommandFlags flags) => { if (key == "Id") { return(volumeReply.Id); } if (key == "Name") { return(volumeReply.Name); } else if (key == "Size") { return(volumeReply.SizeGb); } else if (key == "MountPoints") { return("c:"); } else { throw new Exception(); } }); Mock <IConnectionMultiplexer> connectionMock = new Mock <IConnectionMultiplexer>(); connectionMock.Setup(d => d.GetDatabase(-1, null)).Returns(databaseMock.Object); Mock <IRedisConnectionService> redisServiceMock = new Mock <IRedisConnectionService>(); redisServiceMock.Setup(d => d.Connect()).Returns(connectionMock.Object); Mock <ILogger <VolumesRepository> > loggerMock = new Mock <ILogger <VolumesRepository> >(); VolumesRepository volumeDataSource = new VolumesRepository(redisServiceMock.Object, loggerMock.Object); VolumeReply volume = await volumeDataSource.Get("key", "userId"); Assert.IsTrue(volume.Id.Contains("vol")); Assert.IsTrue(volume.SizeGb == volumeReply.SizeGb); Assert.IsTrue(volume.Name == volumeReply.Name); }
public void Verify_Get_ByKey_Should_ReturnTheCorrectVolume() { // Arrange Mock <IDbSet <Volume> > mockSetVolumes; var mockContext = VolumesMockingSetup.DoMockingSetupForContext(true, out mockSetVolumes); var repository = new VolumesRepository(mockContext.Object); // Act var volumes = repository.Get("KING-STEPHEN"); // Assert Assert.Equal("/TEST/KING-STEPHEN", volumes.ApiDetailUrl); }
public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity() { // Arrange Mock <IDbSet <Volume> > mockSetVolumes; var mockContext = VolumesMockingSetup.DoMockingSetupForContext(true, out mockSetVolumes); var repository = new VolumesRepository(mockContext.Object); var volumes = repository.Get(1); // Act repository.Deactivate(volumes); // Assert Assert.Equal(false, volumes.Active); }
public void Verify_Remove_Should_RemoveTheEntityFromTheContext() { // Arrange Mock <IDbSet <Volume> > mockSetVolumes; var mockContext = VolumesMockingSetup.DoMockingSetupForContext(true, out mockSetVolumes); var repository = new VolumesRepository(mockContext.Object); var volumes = repository.Get(1); // Act repository.Remove(volumes); // Assert mockSetVolumes.Verify(x => x.Remove((Volume)volumes), Times.Once); }
public void Verify_Update_Should_SetTheEntityStateToModified() { // Arrange Mock <IDbSet <Volume> > mockSetVolumes; var mockContext = VolumesMockingSetup.DoMockingSetupForContext(true, out mockSetVolumes); var repository = new VolumesRepository(mockContext.Object); var volumes = repository.Get(1); volumes.ApiDetailUrl = "/TEST"; // Act repository.Update(volumes); // Assert mockContext.Verify(x => x.SetModified(It.IsAny <object>()), Times.Once); }