public void SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__ThrowsInvalidOperationExceptionGivenNonexistentSomething() { int id = 1; int id2 = 5; using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__ThrowsInvalidOperationExceptionGivenNonexistentSomething))) { var persistence = new SomethingElsePersistence(ctx); persistence.SaveSomethingElse(somethingElse); }; Mock <ISomethingFactory> mockSomethingFactory = new Mock <ISomethingFactory>(); mockSomethingFactory.Setup(x => x.Create(something.Name)).Returns((Domain.Something)null); using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__ThrowsInvalidOperationExceptionGivenNonexistentSomething))) { var persistence = new SomethingElsePersistence(ctx); Domain.Something something1 = mockSomethingFactory.Object.Create(something.Name); var exception = Assert.Throws <InvalidOperationException>(() => persistence.UpdateSomethingElseByIdDeleteSomethingById(id, id2)); }; }
public void SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__UpdatesSomethingElseByIdFromDatabaseWithSomethingDeleted() { int id = 1; int something_id = 1; var something1 = new Domain.Something() { Name = "Bob" }; using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__UpdatesSomethingElseByIdFromDatabaseWithSomethingDeleted))) { var persistence = new SomethingElsePersistence(ctx); persistence.SaveSomethingElse(somethingElse); }; using (var ctx = new DbContextFactory().CreateAppDbContext(nameof(SomethingElsePersistence__UpdateSomethingElseByIdDeleteSomethingById__UpdatesSomethingElseByIdFromDatabaseWithSomethingDeleted))) { var persistence = new SomethingElsePersistence(ctx); var updatedSomethingElse = persistence.UpdateSomethingElseByIdDeleteSomethingById(id, something_id); Assert.Equal(somethingElse.Name, updatedSomethingElse.Name); Assert.Equal(somethingElse.Somethings.Count - 1, updatedSomethingElse.Somethings.Count); }; }