public void EnvironmentRepositoryRemoveWithSingleNullExpectedDoesNothing() { var source = new Mock<IEnvironmentModel>(); var repo = new TestEnvironmentRespository(source.Object); var startCount = repo.All().Count; repo.Remove((ICollection<IEnvironmentModel>)null); Assert.AreEqual(startCount, repo.All().Count); Assert.AreEqual(0, repo.RemoveInternalHitCount); Assert.AreEqual(0, repo.WriteSessionHitCount); }
public void EnvironmentRepositoryRemoveWithSingleNonExistingItemExpectedDoesNotRemoveItem() { var source = new Mock<IEnvironmentModel>(); var c1 = CreateMockConnection(); var c2 = CreateMockConnection(); var c3 = CreateMockConnection(); var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var repo = new TestEnvironmentRespository(source.Object, e1, e2); var startCount = repo.All().Count; repo.Remove(e3); Assert.AreEqual(startCount, repo.All().Count); Assert.AreEqual(1, repo.RemoveInternalHitCount); Assert.AreEqual(0, repo.WriteSessionHitCount); }
public void EnvironmentRepositoryRemoveWithSingleItemExpectedDoesNotInvokesWriteSession() { var source = new Mock<IEnvironmentModel>(); var c1 = CreateMockConnection(); var c2 = CreateMockConnection(); var c3 = CreateMockConnection(); var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var repo = new TestEnvironmentRespository(source.Object, e1, e2, e3); repo.Remove(e1); Assert.AreEqual(0, repo.WriteSessionHitCount); }
public void EnvironmentRepositoryRemoveWithSingleItemExpectedDisconnectsAndRemovesItem() { var source = new Mock<IEnvironmentModel>(); var c1 = CreateMockConnection(); var c2 = CreateMockConnection(); var c3 = CreateMockConnection(); c1.Setup(c => c.Disconnect()).Verifiable(); c2.Setup(c => c.Disconnect()).Verifiable(); c3.Setup(c => c.Disconnect()).Verifiable(); var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var repo = new TestEnvironmentRespository(source.Object, e1, e2, e3); repo.Remove(e2); var actual = repo.All().ToList(); c1.Verify(c => c.Disconnect(), Times.Never()); c2.Verify(c => c.Disconnect(), Times.Once()); c3.Verify(c => c.Disconnect(), Times.Never()); Assert.AreEqual(3, actual.Count); Assert.AreEqual(1, repo.RemoveInternalHitCount); Assert.AreSame(source.Object, actual[0]); Assert.AreSame(e1, actual[1]); Assert.AreSame(e3, actual[2]); }
public void EnvironmentRepositoryRemoveWithManyItemsExpectedDoesNotInvokesWriteSession() { var source = new Mock<IEnvironmentModel>(); var e1 = new Mock<IEnvironmentModel>(); var e2 = new Mock<IEnvironmentModel>(); var repo = new TestEnvironmentRespository(source.Object); repo.Remove(new List<IEnvironmentModel> { e1.Object, e2.Object }); Assert.AreEqual(0, repo.WriteSessionHitCount); }
public void EnvironmentRepositoryRemoveWithManyItemsExpectedDisconnectsAndRemovesItems() { // DO NOT use mock as test requires IEquatable of IEnvironmentModel var source = new Mock<IEnvironmentModel>(); var c1 = CreateMockConnection(); var c2 = CreateMockConnection(); var c3 = CreateMockConnection(); c1.Setup(c => c.Disconnect()).Verifiable(); c2.Setup(c => c.Disconnect()).Verifiable(); c3.Setup(c => c.Disconnect()).Verifiable(); var e1 = new EnvironmentModel(Guid.NewGuid(), c1.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e2 = new EnvironmentModel(Guid.NewGuid(), c2.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var e3 = new EnvironmentModel(Guid.NewGuid(), c3.Object, new Mock<IResourceRepository>().Object, new Mock<IStudioResourceRepository>().Object); var repo = new TestEnvironmentRespository(source.Object, e1, e2, e3); repo.Remove(new List<IEnvironmentModel> { e1, e3 }); var actual = repo.All().ToList(); c1.Verify(c => c.Disconnect(), Times.Once()); c2.Verify(c => c.Disconnect(), Times.Never()); c3.Verify(c => c.Disconnect(), Times.Once()); Assert.AreEqual(2, actual.Count); Assert.AreEqual(2, repo.RemoveInternalHitCount); Assert.AreSame(source.Object, actual[0]); Assert.AreSame(e2, actual[1]); }