public void TryReadRecord_OneRecordThatFailsToMap_RecordIsNotReadAndFailureIsReturned() { var record = new object(); var failures = new List <FieldFailure>() { new FieldFailure() }; var readRecord = new Func <object>(() => record); var recordMapper = MockRepository.GenerateMock <IRecordMapper>(); recordMapper.Stub(x => x.TryMap( Arg <object> .Is.Equal(record), out Arg <object> .Out(null).Dummy, out Arg <IEnumerable <FieldFailure> > .Out(failures).Dummy)) .Return(false); var dataReader = new MockDataReader(recordMapper, readRecord); var couldReadRecord = dataReader.TryReadRecord(out var returnedRecord, out var returnedFailures); Assert.IsFalse(couldReadRecord); Assert.IsNull(returnedRecord); Assert.AreEqual(failures, returnedFailures); }
static void Main(string[] args) { var ci = typeof(Data).GetConstructors()[0]; var entries = ci.GetParameters().Select((x, i) => new Factory.MapEntry(i, null)).ToArray(); var factory = new Factory(); var mapper = factory.CreateMapper <Data>(ci, entries); var reader = new MockDataReader( new[] { new MockColumn(typeof(int), "Id"), new MockColumn(typeof(string), "Name"), }, new [] { new object[] { 1, "Test" }, new object[] { DBNull.Value, DBNull.Value }, }); reader.Read(); var entity1 = mapper(reader); reader.Read(); var entity2 = mapper(reader); }
public void testToMeds() { DataTable medTable = new DataTable(); medTable.Columns.Add("RxOutpatSid", typeof(Int64)); medTable.Columns.Add("RxOutpatIEN"); medTable.Columns.Add("Sta3n", typeof(Int16)); medTable.Columns.Add("RxNumber"); medTable.Columns.Add("LocalDrugIEN"); medTable.Columns.Add("IssueDate", typeof(DateTime)); medTable.Columns.Add("MaxRefills", typeof(Int16)); medTable.Columns.Add("RxStatus"); medTable.Columns.Add("LocalDrugNameWithDose"); medTable.Columns.Add("DrugNameWithoutDose"); medTable.Columns.Add("PatientIEN"); medTable.Columns.Add("NationalDrugIEN"); medTable.Rows.Add(new object[] { 800062880992, "7900386", 506, "4238177", "1234509er", DateTime.Now, 5, "ACTIVE", "AMOXICILLIN 500mg", "AMOXICILLIN", "MyIEN", "NatlDrugIEN" }); MockDataReader rdr = new MockDataReader(); rdr.Table = medTable; CdwPharmacyDao dao = new CdwPharmacyDao(new CdwConnection(new DataSource() { ConnectionString = "myCxnString" })); Medication[] results = dao.toMeds(rdr); Assert.AreEqual(results.Length, 1); Assert.IsTrue(String.Equals(results[0].RxNumber, "4238177")); Assert.IsTrue(String.Equals(results[0].Status, "ACTIVE")); }
static void Main(string[] args) { var colmuns = new ColumnInfo[] { new ColumnInfo("Id", typeof(int)), new ColumnInfo("Name", typeof(string)), new ColumnInfo("Id", typeof(int)), new ColumnInfo("Name", typeof(string)) }; var reader = new MockDataReader( colmuns.Select(x => new MockColumn(x.Type, x.Name)).ToArray(), new [] { new object[] { 1, "Master-1", 101, "Slave1" }, new object[] { 1, "Master-1", 102, "Slave2" }, new object[] { DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value } }); var context = new DummyContext(); var mi = typeof(Program).GetMethod(nameof(Main)); var tupleMapper = TupleResultMapperFactory.Instance.CreateMapper <Tuple <Master, Slave> >(context, mi, colmuns); reader.Read(); var t1 = tupleMapper(reader); }
public void CanReadAllDataProperly() { var builder = new SimpleMockDataReaderBuilder(). SetNullValueHandling(NullValueHandling.AssumeAsDbNull). AddColumn("ID_PRODUCT", typeof(long)). AddColumn("PRODUCT_NAME", typeof(string)). AddColumn("IS_ACTIVE", typeof(bool)). AddColumn("BARCODE", typeof(string)). AddData(1L, "Product 1", true, null); using (var reader = new MockDataReader(builder)) { reader.Read(); reader.IsDBNull(0).ShouldBe <bool>(false); reader.GetInt64(0).ShouldBe <long>(1); reader.GetValue(0).ShouldBe <object>(1); reader["ID_PRODUCT"].ShouldBe <object>(1); reader.IsDBNull(1).ShouldBe <bool>(false); reader.GetString(1).ShouldBe <string>("Product 1"); reader.GetValue(1).ShouldBe <object>("Product 1"); reader["PRODUCT_NAME"].ShouldBe <object>("Product 1"); reader.IsDBNull(2).ShouldBe <bool>(false); reader.GetBoolean(2).ShouldBe <bool>(true); reader.GetValue(2).ShouldBe <object>(true); reader["IS_ACTIVE"].ShouldBe <object>(true); reader.IsDBNull(3).ShouldBe <bool>(true); reader.GetValue(3).ShouldBe <object>(DBNull.Value); reader["BARCODE"].ShouldBe <object>(DBNull.Value); } }
public virtual object query(SqlDataAdapter adapter, AbstractPermission permission = null) { Impersonator imp = null; try { if (_impersonationUser != null) { imp = new Impersonator(_impersonationUser); } using (SqlConnection newCxn = new SqlConnection(this.DataSource.ConnectionString)) { newCxn.Open(); if (adapter.SelectCommand != null) { adapter.SelectCommand.Connection = newCxn; //DataSet results = new DataSet(); //adapter.Fill(results); //return results; SqlDataReader rdr = adapter.SelectCommand.ExecuteReader(); // the SqlDataReader will be closed at the exit of this using block so we copy everything over to our MockDataReader where it will be cached in a DataTable MockDataReader mock = new MockDataReader(); DataTable newTable = new DataTable(); newTable.Load(rdr); mock.Table = newTable; // the previous couple lines are broken out so the setter on MockDataReader.Table can properly map the column names - IMPORTANT!! return(mock); } else if (adapter.DeleteCommand != null) { adapter.DeleteCommand.Connection = newCxn; return(adapter.DeleteCommand.ExecuteNonQuery()); } else if (adapter.UpdateCommand != null) { adapter.UpdateCommand.Connection = newCxn; return(adapter.UpdateCommand.ExecuteNonQuery()); } else if (adapter.InsertCommand != null) { adapter.InsertCommand.Connection = newCxn; return(adapter.InsertCommand.ExecuteNonQuery()); } throw new ArgumentException("Must supply a SQL command"); } } catch (Exception) { throw; } finally { if (imp != null) { imp.stopImpersonation(); } } }
public void CanReadAllDataProperly() { var dataList = new List <TestObjectClass>(); dataList.Add(new TestObjectClass { IntProperty = 10, StringProperty = "ten" }); dataList.Add(new TestObjectClass { IntProperty = 20, StringProperty = "twenty" }); dataList.Add(new TestObjectClass { IntProperty = 30, StringProperty = "thirty" }); var builder = new ObjectBasedMockDataReaderBuilder <TestObjectClass>(). SetNullValueHandling(NullValueHandling.AssumeAsDbNull). AddData(dataList); using (var reader = new MockDataReader(builder)) { reader.Read().ShouldBe <bool>(true); reader.Read().ShouldBe <bool>(true); reader.IsDBNull(0).ShouldBe(false); reader.GetInt32(0).ShouldBe <int>(20); reader.GetValue(0).ShouldBe <object>(20); reader.IsDBNull(1).ShouldBe <bool>(false); reader.GetString(1).ShouldBe <string>("twenty"); reader.GetValue(1).ShouldBe <object>("twenty"); } }
public void TryToMapNullableToNonNullable() { var reader = new MockDataReader(_testData); reader.Read(); Assert.Throws(typeof(NullReferenceException), () => SqlMapper.MapObjectWithCachedReflection <IncorrectModelNonNullable>(reader)); }
public void TryToMapNullableToNonNullable_Reflection() { var reader = new MockDataReader(_testData); reader.Read(); Assert.That(() => SqlMapper.MapObjectWithReflection <IncorrectModelNonNullable>(reader), Throws.ArgumentException); }
public void MapObjectWithCachedReflection() { var reader = new MockDataReader(_testData); reader.Read(); var model = SqlMapper.MapObjectWithCachedReflection <SqlMapperTestModel>(reader); AssertFirstModel(model); }
public void IncorrectModelTest() { // no problem here - reader throws the error with unknown column name var reader = new MockDataReader(_testData); reader.Read(); Assert.That(() => SqlMapper.MapObjectWithCachedReflection <IncorrectModel>(reader), Throws.ArgumentException); }
public void Dispose_Dispose_CloseIsCalled() { var closeWasCalled = false; var close = new Action(() => closeWasCalled = true); var dataReader = new MockDataReader(close); dataReader.Dispose(); Assert.IsTrue(closeWasCalled); }
public void TryReadRecord_ReadRecordInternalThrowsException_ExceptionIsPropogated() { var readRecord = new Func <object>(() => { throw new InternalTestFailureException(); }); var dataReader = new MockDataReader(readRecord); dataReader.TryReadRecord(out var record, out var failures); }
public void WillBuildItemWithoutValueFactoriesAndNoPrefix() { TestClass expected = null; MockDataReader reader = null; expected = ObjectCreator.CreateNew <TestClass>(); reader = new MockDataReaderHelper().BuildMockDataReader(new[] { expected }); var actual = SystemUnderTest.Build <TestClass>(reader); Asserter.AssertEquality(expected, actual); }
public void WillBuildItemWithoutValueFactoriesAndPrefix() { TestClass expected = null; MockDataReader reader = null; var prefix = String.Empty; prefix = DataGenerator.GenerateString(); expected = ObjectCreator.CreateNew <TestClass>(); reader = new MockDataReaderHelper().BuildMockDataReader(new[] { expected }, prefix); var actual = SystemUnderTest.Build <TestClass>(reader, prefix); Asserter.AssertEquality(expected, actual); }
public void TryReadRecord_OneRecordWithRecordMapper_RecordIsMappedAndRead() { var recordsRead = 0; var records = new List <object>() { new object() }; var mappedRecords = new List <object>() { new object() }; var readRecord = new Func <object>(() => { if (recordsRead == 1) { return(null); } return(records[recordsRead++]); }); var recordMapper = MockRepository.GenerateMock <IRecordMapper>(); recordMapper.Expect(x => x.TryMap( Arg <object> .Is.Equal(records[0]), out Arg <object> .Out(mappedRecords[0]).Dummy, out Arg <IEnumerable <FieldFailure> > .Out(null).Dummy)) .Return(true) .Repeat.Once(); var dataReader = new MockDataReader(recordMapper, readRecord); bool couldReadRecord; IEnumerable <FieldFailure> failures; do { couldReadRecord = dataReader.TryReadRecord(out var record, out failures); if (couldReadRecord) { Assert.AreEqual(mappedRecords[recordsRead - 1], record); Assert.IsNull(failures); } }while (couldReadRecord || failures?.Count() > 0); recordMapper.VerifyAllExpectations(); Assert.AreEqual(records.Count, recordsRead); }
public void TryReadRecord_ZeroRecords_NoRecordsAreRead() { var readRecord = new Func <object>(() => { return(null); }); var dataReader = new MockDataReader(readRecord); var couldReadRecord = dataReader.TryReadRecord(out var record, out var failures); Assert.IsFalse(couldReadRecord); Assert.IsNull(failures); }
public void WillThrowInvalidOperationExceptionIfTypeDoesNotHavePrimaryKey() { dynamic parameters = null; MockDataReader reader = null; parameters = new ExpandoObject(); parameters.TableObjectMappings = CreateEnumerableOfItems <TableObjectMapping>().ToList(); reader = new MockDataReader(); Asserter .AssertException <InvalidOperationException>( () => SystemUnderTest.BuildItems <ClassWithNoPrimaryKey>(parameters, reader)) .AndVerifyMessageContains("Type {0} either has no FieldMetaDataAttributes or no Primary Key defined." .FormatString(typeof(ClassWithNoPrimaryKey).ToString())); }
// use the profiler to see run times of each of the mapping methods. Stopwatch is misleading... public static void Run() { var testTable = CreateTestTable(); var stopwatch = new Stopwatch(); var models = new List <SqlMapperTestModel>(); var reader = new MockDataReader(testTable); stopwatch.Start(); while (reader.Read()) { models.Add(MapModelHardCoded(reader)); } stopwatch.Stop(); var hardCodedMs = stopwatch.ElapsedMilliseconds; Console.WriteLine($"Using hard coded: read {NumTestRecords} in {hardCodedMs} ms"); models.Clear(); reader = new MockDataReader(testTable); stopwatch.Reset(); stopwatch.Start(); while (reader.Read()) { models.Add(SqlMapper.MapObjectWithCachedReflection <SqlMapperTestModel>(reader)); } stopwatch.Stop(); var timesHardCodedMs = (float)stopwatch.ElapsedMilliseconds / hardCodedMs; Console.WriteLine($"Using cached expressions: read {NumTestRecords} in {stopwatch.ElapsedMilliseconds} ms ({timesHardCodedMs}x) "); models.Clear(); reader = new MockDataReader(testTable); stopwatch.Reset(); stopwatch.Start(); while (reader.Read()) { models.Add(SqlMapper.MapObjectWithReflection <SqlMapperTestModel>(reader)); } stopwatch.Stop(); timesHardCodedMs = (float)stopwatch.ElapsedMilliseconds / hardCodedMs; Console.WriteLine($"Using pure reflection: read {NumTestRecords} in {stopwatch.ElapsedMilliseconds} ms ({timesHardCodedMs}x)"); }
private IDataBlock ScanDataBlock(byte[] byteStream, IScanContext scanContext) { scanContext.Detectors = new[] { _videoDetector }; IDataBlockBuilder builder = TestFramework.CreateDataBlockBuilder(); builder.Detectors = scanContext.Detectors; var inputFile = _mockRepository.StrictMock <IInputFile>(); With.Mocks(_mockRepository).Expecting(delegate { SetupResult.For(inputFile.Name).Return("<ByteArrayDataReader>"); SetupResult.For(inputFile.Length).Return(byteStream.Length); }); builder.InputFile = inputFile; var mockDataReader = new MockDataReader(byteStream, inputFile); IDataBlock dataBlock = _videoDetector.DetectData(mockDataReader, builder, scanContext); Assert.IsNotNull(dataBlock); return(dataBlock); }
public void testToMessageFromReaderComplete() { MockDataReader rdr = new MockDataReader(); DataTable table = new DataTable(); foreach (string columnName in TableSchemas.SECURE_MESSAGE_COLUMNS) { table.Columns.Add(columnName); } rdr.Table = table; object[] fakeValues = new object[] { 1, 2, DateTime.Now, 4, "ABCD1234", 6, 7, 8, 9, DateTime.Now, DateTime.Now, DateTime.Now, DBNull.Value, DateTime.Now, 15, 16, "BUTTS,SEYMOUR", 18, 19, "HUMPALOT,YVONNA", DateTime.Now, DateTime.Now, DBNull.Value, 0, 0 }; rdr.Table.Rows.Add(fakeValues); rdr.Read(); domain.sm.Message result = domain.sm.Message.getMessageFromReader(rdr); Assert.IsNotNull(result); }
public void ValidUser() { MockLogger3 logger = new MockLogger3(); logger.ExpectedName = "AccessControl"; logger.AddExpectedMsg( "Checking access for dave to secrets"); logger.AddExpectedMsg("Access granted"); // set up the mock database MockDbConnection conn = new MockDbConnection(); MockCommand cmd = new MockCommand(); MockDataReader rdr = new MockDataReader(); conn.SetExpectedCommand(cmd); cmd.SetExpectedCommandText( AccessController1.CHECK_SQL); cmd.SetExpectedExecuteCalls(1); cmd.SetExpectedParameter( new MockDataParameter("@user", "dave")); cmd.SetExpectedParameter( new MockDataParameter("@password", "shhh")); cmd.SetExpectedParameter( new MockDataParameter("@resource", "secrets")); cmd.SetExpectedReader(rdr); object [,] rows = new object[1,1]; rows[0, 0] = 1; rdr.SetRows(rows); AccessController1 access = new AccessController1("secrets", logger, conn); Assert.That( access.CanAccess("dave", "shhh"), Is.True ); logger.Verify(); conn.Verify(); cmd.Verify(); }
public void TryReadRecord_MultipleRecords_AllRecordsAreRead() { var recordsRead = 0; var records = new List <object>() { new object(), new object(), new object() }; var readRecord = new Func <object>(() => { if (recordsRead == records.Count) { return(null); } return(records[recordsRead++]); }); var dataReader = new MockDataReader(readRecord); bool couldReadRecord; IEnumerable <FieldFailure> failures; do { couldReadRecord = dataReader.TryReadRecord(out var record, out failures); if (couldReadRecord) { Assert.AreEqual(records[recordsRead - 1], record); Assert.IsNull(failures); } }while (couldReadRecord || failures?.Count() > 0); Assert.AreEqual(records.Count, recordsRead); }
public override object query(string request, AbstractPermission permission = null) { Impersonator imp = null; try { if (_impersonationUser != null) { imp = new Impersonator(_impersonationUser); } using (SqlConnection newCxn = new SqlConnection(this.DataSource.ConnectionString)) { newCxn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = newCxn; cmd.CommandText = request; cmd.CommandTimeout = 60 * 10; SqlDataReader rdr = cmd.ExecuteReader(); // the SqlDataReader will be closed at the exit of this using block so we copy everything over to our MockDataReader where it will be cached in a DataTable MockDataReader mock = new MockDataReader(); DataTable newTable = new DataTable(); newTable.Load(rdr); mock.Table = newTable; // the previous couple lines are broken out so the setter on MockDataReader.Table can properly map the column names - IMPORTANT!! return(mock); } } catch (Exception) { throw; } finally { if (imp != null) { imp.stopImpersonation(); } } }
public void WillBuildItemWithValueFactories() { TestClass expected = null; MockDataReader reader = null; Mock <IValueFactory> valueFactory = null; var valueFactoryModel = ObjectCreator.CreateNew <TestClassWithValueFactories>(); expected = ObjectCreator.CreateNew <TestClass>(); reader = new MockDataReaderHelper().BuildMockDataReader(new [] { valueFactoryModel }); valueFactory = Mocks.Get <IValueFactory>(); Expression <Func <object> > fakeExpression = () => expected; valueFactory .Setup(x => x.GetValueFactory(It.IsAny <string>(), It.IsAny <ParameterInfo>())) .Returns(fakeExpression); var actual = SystemUnderTest.Build <TestClassWithValueFactories>(reader); valueFactory .Verify(x => x.GetValueFactory("TestClass1", It.IsAny <ParameterInfo>()), Times.Once); valueFactory .Verify(x => x.GetValueFactory("TestClass2", It.IsAny <ParameterInfo>()), Times.Once); Assert.IsFalse(actual.ValueFactories.IsNullOrEmpty()); Assert.IsTrue(actual.ValueFactories.ContainsKey("TestClass1")); Assert.IsNotNull(actual.ValueFactories["TestClass1"]); Asserter.AssertEquality(expected, actual.TestClass1); Assert.IsTrue(actual.ValueFactories.ContainsKey("TestClass2")); Assert.IsNotNull(actual.ValueFactories["TestClass2"]); Asserter.AssertEquality(expected, actual.TestClass2); }
public void testToMessageFromReaderSparse() { MockDataReader rdr = new MockDataReader(); DataTable table = new DataTable(); for (int i = 0; i < TableSchemas.SECURE_MESSAGE_COLUMNS.Count; i++) { if (i % 2 == 0) // just add the even indices to simulate randomly chosen columns { table.Columns.Add(TableSchemas.SECURE_MESSAGE_COLUMNS[i]); } } rdr.Table = table; object[] fakeValues = new object[] { 1, DateTime.Now, "ABCD1234", 7, 9, DateTime.Now, DBNull.Value, 15, "BUTTS,SEYMOUR", 19, DateTime.Now, DBNull.Value, 0 }; rdr.Table.Rows.Add(fakeValues); rdr.Read(); domain.sm.Message result = domain.sm.Message.getMessageFromReader(rdr); Assert.IsNotNull(result); }
public void WillBuildItems() { List <Parent> expected = null; MockDataReader reader = null; dynamic parameters = null; expected = new List <Parent>(); parameters = new ExpandoObject(); var dataReaderBuilder = Mocks.Get <IDataReaderBuilder>(); var tableObjectMappings = new List <TableObjectMapping> { new TableObjectMapping { Prefix = "t1" }, new TableObjectMapping { Prefix = "t2", InstancePropertyName = "Child1s", ParentKey = "ParentId", ChildKey = "ParentId", JoinType = typeof(Child1) }, new TableObjectMapping { Prefix = "t3", InstancePropertyName = "Child2s", ParentKey = "ParentId", ChildKey = "ParentId", JoinType = typeof(Child2) } }; parameters.TableObjectMappings = tableObjectMappings; var parent1Id = Guid.NewGuid(); var parent2Id = Guid.NewGuid(); var parent1 = new Parent { Id = parent1Id, ParentName = "Parent1", Child1s = new List <Child1> { new Child1 { Id = Guid.NewGuid(), ParentId = parent1Id, Child1Name = "Parent1Child1_1" }, new Child1 { Id = Guid.NewGuid(), ParentId = parent1Id, Child1Name = "Parent1Child1_2" } }, Child2s = new List <Child2> { new Child2 { Id = Guid.NewGuid(), ParentId = parent1Id, Child2Name = "Parent1Child2_1" }, new Child2 { Id = Guid.NewGuid(), ParentId = parent1Id, Child2Name = "Parent1Child2_2" } } }; expected.Add(parent1); var parent2 = new Parent { Id = parent2Id, ParentName = "Parent2", Child1s = new List <Child1> { new Child1 { Id = Guid.NewGuid(), ParentId = parent2Id, Child1Name = "Parent2Child1_1" }, new Child1() { Id = Guid.NewGuid(), ParentId = parent2Id, Child1Name = "Parent2Child1_2" } }, Child2s = new List <Child2> { new Child2 { Id = Guid.NewGuid(), ParentId = parent2Id, Child2Name = "Parent2Child2_1" }, new Child2 { Id = Guid.NewGuid(), ParentId = parent2Id, Child2Name = "Parent2Child2_2" } } }; expected.Add(parent2); reader = new MockDataReader(new DataContainer(4, new[] { new ColumnInfo("t1_Id", new object[] { parent1.Id, parent1.Id, parent2.Id, parent2.Id }), new ColumnInfo("t1_ParentName", new object[] { parent1.ParentName, parent1.ParentName, parent2.ParentName, parent2.ParentName }), new ColumnInfo("t2_Id", new object[] { parent1.Child1s.First().Id, parent1.Child1s.Last().Id, parent2.Child1s.First().Id, parent2.Child1s.Last().Id }), new ColumnInfo("t2_ParentId", new object[] { parent1.Child1s.First().ParentId, parent1.Child1s.Last().ParentId, parent2.Child1s.First().ParentId, parent2.Child1s.Last().ParentId }), new ColumnInfo("t2_Child1Name", new object[] { parent1.Child1s.First().Child1Name, parent1.Child1s.Last().Child1Name, parent2.Child1s.First().Child1Name, parent2.Child1s.Last().Child1Name }), new ColumnInfo("t3_Id", new object[] { parent1.Child2s.First().Id, parent1.Child2s.Last().Id, parent2.Child2s.First().Id, parent2.Child2s.Last().Id }), new ColumnInfo("t3_ParentId", new object[] { parent1.Child2s.First().ParentId, parent1.Child2s.Last().ParentId, parent2.Child2s.First().ParentId, parent2.Child2s.Last().ParentId }), new ColumnInfo("t3_Child2Name", new object[] { parent1.Child2s.First().Child2Name, parent1.Child2s.Last().Child2Name, parent2.Child2s.First().Child2Name, parent2.Child2s.Last().Child2Name }) })); var parent1NoChildren = parent1.ShallowCopy(); var parent2NoChildren = parent2.ShallowCopy(); parent1NoChildren.Child1s = null; parent1NoChildren.Child2s = null; parent2NoChildren.Child1s = null; parent2NoChildren.Child2s = null; dataReaderBuilder .Setup(x => x.Build <Parent>(reader, "t1", false)) .ReturnsInOrder(new [] { parent1NoChildren, parent1NoChildren, parent2NoChildren, parent2NoChildren }); dataReaderBuilder .Setup(x => x.Build <Child1>(reader, "t2", false)) .ReturnsInOrder(new [] { parent1.Child1s.First(), parent1.Child1s.Last(), parent2.Child1s.First(), parent2.Child1s.Last() }); dataReaderBuilder .Setup(x => x.Build <Child2>(reader, "t3", false)) .ReturnsInOrder(new [] { parent1.Child2s.First(), parent1.Child2s.Last(), parent2.Child2s.First(), parent2.Child2s.Last() }); var actual = SystemUnderTest.BuildItems <Parent>(parameters, reader); Expression <Action <Parent, Parent> > compareParent = (e, a) => Asserter.AssertEquality(e, a, new[] { "Child1s", "Child2s" }, null, It.IsAny <bool>()); Expression <Action <Child1, Child1> > compareChild1s = (e, a) => Asserter.AssertEquality(e, a, null, null, It.IsAny <bool>()); Expression <Action <Child2, Child2> > compareChild2s = (e, a) => Asserter.AssertEquality(e, a, null, null, It.IsAny <bool>()); Asserter.AssertEquality(expected, actual, additionalParameters: new Dictionary <string, object> { { Norml.Tests.Common.Constants.ParameterNames.ComparisonDelegate, compareParent } }); IEnumerable <Child1> firstExpectedChild1s = ((IEnumerable <Parent>)expected).First().Child1s; IEnumerable <Child1> firstActualChild1s = ((IEnumerable <Parent>)actual).First().Child1s; Asserter.AssertEquality(firstExpectedChild1s, firstActualChild1s, additionalParameters: new Dictionary <string, object> { { Norml.Tests.Common.Constants.ParameterNames.ComparisonDelegate, compareChild1s } }); IEnumerable <Child2> firstExpectedChild2s = ((IEnumerable <Parent>)expected).First().Child2s; IEnumerable <Child2> firstActualChild2s = ((IEnumerable <Parent>)actual).First().Child2s; Asserter.AssertEquality(firstExpectedChild2s, firstActualChild2s, additionalParameters: new Dictionary <string, object> { { Norml.Tests.Common.Constants.ParameterNames.ComparisonDelegate, compareChild2s } }); IEnumerable <Child1> lastExpectedChild1s = ((IEnumerable <Parent>)expected).Last().Child1s; IEnumerable <Child1> lastActualChild1s = ((IEnumerable <Parent>)actual).Last().Child1s; Asserter.AssertEquality(lastExpectedChild1s, lastActualChild1s, additionalParameters: new Dictionary <string, object> { { Norml.Tests.Common.Constants.ParameterNames.ComparisonDelegate, compareChild1s } }); IEnumerable <Child2> lastExpectedChild2s = ((IEnumerable <Parent>)expected).Last().Child2s; IEnumerable <Child2> lastActualChild2s = ((IEnumerable <Parent>)actual).Last().Child2s; Asserter.AssertEquality(lastExpectedChild2s, lastActualChild2s, additionalParameters: new Dictionary <string, object> { { Norml.Tests.Common.Constants.ParameterNames.ComparisonDelegate, compareChild2s } }); }
public void Setup() { _reader = new MockDataReader(_readerTable); }
public void testToMessageFromReaderSparse() { MockDataReader rdr = new MockDataReader(); DataTable table = new DataTable(); for(int i = 0; i < TableSchemas.SECURE_MESSAGE_COLUMNS.Count; i++) { if (i % 2 == 0) // just add the even indices to simulate randomly chosen columns { table.Columns.Add(TableSchemas.SECURE_MESSAGE_COLUMNS[i]); } } rdr.Table = table; object[] fakeValues = new object[] { 1, DateTime.Now, "ABCD1234", 7, 9, DateTime.Now, DBNull.Value, 15, "BUTTS,SEYMOUR", 19, DateTime.Now, DBNull.Value, 0 }; rdr.Table.Rows.Add(fakeValues); rdr.Read(); domain.sm.Message result = domain.sm.Message.getMessageFromReader(rdr); Assert.IsNotNull(result); }