public void EntityWithNoPrimaryKeyValue_CallsQueryComposerComposeInsertWithPropertiesExcludingThePrimaryKey() { // Arrange var repository = TestableRepository<TestEntity1>.Create(); var entity = new TestEntity1(); // Act repository.Create(entity); // Assert repository.MockQueryComposer .Verify(x => x.ComposeInsert(entity.GetType(), "TestEntity1Id"), Times.Once()); }
public void Entity_CallsQueryComposerComposeDelete() { // Arrange var repository = TestableRepository<TestEntity1>.Create(); var entity = new TestEntity1(); // Act repository.Delete(entity); // Assert repository.MockQueryComposer .Verify(x => x.ComposeDelete(entity.GetType(), "TestEntity1Id"), Times.Once()); }
public void Entity_AfterInsertReturnsEntityWithThePrimaryKeyPropertyContainingIdentityValue() { // Arrange var repository = TestableRepository<TestEntity1>.Create(); var entity = new TestEntity1(); repository.MockConductor .Setup(x => x.ExecuteScalar<object>(It.IsAny<string>(), It.IsAny<object>())) .Returns(123); // Act repository.Create(entity); // Assert Assert.AreEqual(123, entity.TestEntity1Id); }
public void Entity_CallsConductorExecuteScalarWithCorrectlyComposedInserQuery() { // Arrange var repository = TestableRepository<TestEntity1>.Create(); var entity = new TestEntity1(); var insertQuery = "INSERT INTO TestEntity1 (TestEntity1Id, TestPropertyString, TestPropertyInt, TestPropertyDateTime) VALUES (@TestEntity1Id, @TestPropertyString, @TestPropertyInt, @TestPropertyDateTime)"; repository.MockQueryComposer .Setup(x => x.ComposeInsert(entity.GetType(), It.IsAny<string>())) .Returns(insertQuery); // Act repository.Create(entity); // Assert repository.MockConductor .Verify(x => x.ExecuteScalar<object>(insertQuery, entity), Times.Once()); }
public void Entity_CallsConductorExecuteWithCorrectlyComposedDeleteQuery() { // Arrange var repository = TestableRepository<TestEntity1>.Create(); var entity = new TestEntity1(); var deleteQuery = "DELETE FROM TestEntity1 WHERE TestEntity1Id = @TestEntity1Id"; repository.MockQueryComposer .Setup(x => x.ComposeDelete(entity.GetType(), "TestEntity1Id")) .Returns(deleteQuery); // Act repository.Delete(entity); // Assert repository.MockConductor .Verify(x => x.Execute(deleteQuery, entity), Times.Once()); }
public void Entity_CallsConductorExecuteWithCorrectlyComposedUpdateQuery() { // Arrange var repository = TestableRepository<TestEntity1>.Create(); var entity = new TestEntity1(); var updateQuery = "UPDATE TestEntity1 SET TestPropertyString = @TestPropertyString, TestPropertyInt = @TestPropertyInt, TestPropertyDateTime = @TestPropertyDateTime WHERE TestEntity1Id = @TestEntity1Id"; repository.MockQueryComposer .Setup(x => x.ComposeUpdate(entity.GetType(), "TestEntity1Id")) .Returns(updateQuery); // Act repository.Update(entity); // Assert repository.MockConductor .Verify(x => x.Execute(updateQuery, entity), Times.Once()); }