public void Add_Test() { // Arrange var expected = new SubjectClass(); var populator = new StandardPopulator(Helpers.GetTypeGeneratorMock(expected).Object, new MockPersistence(), this.attributeDecorator, null, null, null); // Act RecordReference<SubjectClass> reference = populator.Add<SubjectClass>(); populator.Bind(); // Assert Assert.IsNotNull(reference); Assert.AreEqual(expected.GetType(), reference.RecordType); Assert.AreEqual(expected, reference.RecordObject); }
public void Initialize() { XmlConfigurator.Configure(); this.attributeDecorator = new StandardAttributeDecorator(attributeDecorator => null, null); this.subject = new SubjectClass(); this.recordReferenceMock = new Mock<RecordReference>(null, this.attributeDecorator); this.peers = new List<AbstractRepositoryOperation>(); this.serviceMock = new Mock<InsertRecordService>(this.recordReferenceMock.Object, this.attributeDecorator, true); this.insertRecord = new InsertRecord(this.serviceMock.Object, this.recordReferenceMock.Object, this.peers, this.attributeDecorator); this.breakerMock = new Mock<CircularReferenceBreaker>(); this.writePrimitivesMock = new Mock<IWritePrimitives>(); this.recordReferenceMock.Setup(m => m.RecordObject).Returns(this.subject); this.recordReferenceMock.Setup(m => m.RecordType).Returns(this.subject.GetType()); }
public void Records_Cleared_After_Bind_Test() { // Arrange var expected = new SubjectClass { AnEmailAddress = "email"}; var mockPersistence = new MockPersistence(); var populator = new StandardPopulator(Helpers.GetTypeGeneratorMock(expected).Object, mockPersistence, this.attributeDecorator, null, null, null); // Act populator.Add<SubjectClass>(); populator.Bind(); populator.Add<SubjectClass>(); populator.Bind(); RecordReference<SubjectClass> reference = populator.Add<SubjectClass>(); populator.Bind(); // Assert Assert.AreEqual(1, mockPersistence.Storage.Count); Assert.AreEqual(reference.RecordObject.AnEmailAddress, mockPersistence.Storage[0]["AnEmailAddress"]); }
public void WriteOperationOrder_Test() { // Arrange var orderedOpertations = new AbstractRepositoryOperation[2]; var secondObject = new SubjectClass(); var secondrecordReferenceMock = new Mock<RecordReference>(null, this.attributeDecorator); secondrecordReferenceMock.Setup(m => m.RecordObject).Returns(secondObject); secondrecordReferenceMock.Setup(m => m.RecordType).Returns(secondObject.GetType()); var secondInsertRecord = new InsertRecord(this.serviceMock.Object, secondrecordReferenceMock.Object, this.peers, this.attributeDecorator); var primaryKeyOperations = new List<InsertRecord> { secondInsertRecord }; var regularColumns = new List<Column>(); var foreignKeyColumns = new List<ExtendedColumnSymbol>(); this.serviceMock.Setup(m => m.GetPrimaryKeyOperations(this.peers)).Returns(primaryKeyOperations); this.serviceMock.Setup(m => m.GetRegularColumns(this.writePrimitivesMock.Object)).Returns(regularColumns); this.serviceMock.Setup(m => m.GetForeignKeyColumns(primaryKeyOperations)).Returns(foreignKeyColumns); this.serviceMock.Setup( m => m.WritePrimaryKeyOperations(It.IsAny<IWritePrimitives>(), It.IsAny<IEnumerable<AbstractRepositoryOperation>>(), It.IsAny<CircularReferenceBreaker>(), It.IsAny<Counter>(), It.IsAny<AbstractRepositoryOperation[]>())) .Callback <IWritePrimitives, IEnumerable<AbstractRepositoryOperation>, CircularReferenceBreaker, Counter, AbstractRepositoryOperation[]>( (writer, secondPrimaryKeyOperations, breaker, secondCurrentOrder, secondOrderedOperations) => { this.serviceMock.Setup( n => n.WritePrimaryKeyOperations(It.IsAny<IWritePrimitives>(), It.IsAny<IEnumerable<InsertRecord>>(), It.IsAny<CircularReferenceBreaker>(), It.IsAny<Counter>(), It.IsAny<AbstractRepositoryOperation[]>())); secondInsertRecord.Write(breaker, writer, secondCurrentOrder, secondOrderedOperations); }); // Act this.insertRecord.Write(this.breakerMock.Object, this.writePrimitivesMock.Object, new Counter(), orderedOpertations); // Assert Assert.AreEqual(secondInsertRecord, orderedOpertations[0]); Assert.AreEqual(this.insertRecord, orderedOpertations[1]); }
public void StandardPopulatorTest_Bind() { // Arrange const int integer = 5; const string text = "abcde"; var persistence = new MockPersistence(); var inputRecord = new SubjectClass {Integer = integer, Text = text,}; Mock<ITypeGenerator> typeGeneratorMock = Helpers.GetTypeGeneratorMock(inputRecord); var populator = new StandardPopulator(typeGeneratorMock.Object, persistence, this.attributeDecorator, null, null, null); // Act populator.Add<SubjectClass>(); populator.Bind(); // Assert IDictionary<string, object> record = persistence.Storage.FirstOrDefault(); Assert.IsNotNull(record); Assert.AreEqual(record["Integer"], integer); Assert.AreEqual(record["Text"], text); }