public void should_populate_on_setup() { var mockTypeLookup = Substitute.For <IComponentTypeLookup>(); mockTypeLookup.GetComponentType(typeof(TestStructComponentOne)).Returns(0); mockTypeLookup.GetComponentType(typeof(TestStructComponentTwo)).Returns(1); var mockComponentPool1 = Substitute.For <IComponentPool <TestStructComponentOne> >(); mockComponentPool1.OnPoolExtending.Returns(Observable.Empty <bool>()); var mockComponentPool2 = Substitute.For <IComponentPool <TestStructComponentTwo> >(); mockComponentPool2.OnPoolExtending.Returns(Observable.Empty <bool>()); var mockComponentDatabase = Substitute.For <IComponentDatabase>(); mockComponentDatabase.GetPoolFor <TestStructComponentOne>(0).Returns(mockComponentPool1); mockComponentDatabase.GetPoolFor <TestStructComponentTwo>(1).Returns(mockComponentPool2); var mockObservableGroup = Substitute.For <IObservableGroup>(); mockObservableGroup.OnEntityAdded.Returns(Observable.Empty <IEntity>()); mockObservableGroup.OnEntityRemoving.Returns(Observable.Empty <IEntity>()); mockObservableGroup.OnEntityRemoved.Returns(Observable.Empty <IEntity>()); var mockBatchBuilder = Substitute.For <IBatchBuilder <TestStructComponentOne, TestStructComponentTwo> >(); var batchAccessor = new BatchAccessor <TestStructComponentOne, TestStructComponentTwo>(mockObservableGroup, mockComponentDatabase, mockBatchBuilder, mockTypeLookup); mockBatchBuilder.Received(1).Build(mockObservableGroup); }
public void BatchAccessor_Construction_1() { Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchAccessor batch = new BatchAccessor(connection); Assert.AreSame(connection, batch.Connection); }
public void BatchAccessor_ReadRecords_1() { Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchAccessor batch = new BatchAccessor(connection); int[] mfnList = new int[0]; MarcRecord[] records = batch.ReadRecords("IBIS", mfnList); Assert.AreEqual(0, records.Length); }
public void BatchAccessor_ReadRecords_7() { Mock <IIrbisConnection> mock = new Mock <IIrbisConnection>(); IIrbisConnection connection = mock.Object; mock.SetupGet(c => c.CommandFactory) .Returns(new CommandFactory(connection)); mock.Setup(c => c.ExecuteCommand(It.IsAny <AbstractCommand>())) .Returns((FormatCommand command) => ExecuteFormatCommand(command, true)); BatchAccessor batch = new BatchAccessor(connection); int[] mfnList = { 1, 2, 3 }; batch.ReadRecords("IBIS", mfnList); }
public void BatchAccessor_ReadRecords_2() { Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchAccessor batch = new BatchAccessor(connection); int[] mfnList = { 1 }; MarcRecord[] records = batch.ReadRecords("IBIS", mfnList); Assert.AreEqual(1, records.Length); Assert.AreEqual(1, records[0].Mfn); mock.Verify(c => c.ReadRecord(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>()), Times.Once); }
public void BatchAccessor_ReadRecords_4() { Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchAccessor batch = new BatchAccessor(connection); int[] mfnList = new int[0]; int[] records = batch.ReadRecords("IBIS", mfnList, RecordToMfn); Assert.AreEqual(0, records.Length); mock.Verify(c => c.ReadRecord(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>()), Times.Never); mock.Verify(c => c.ExecuteCommand(It.IsAny <AbstractCommand>()), Times.Never); }
public void BatchAccessor_ReadRecords_3() { Mock <IIrbisConnection> mock = GetMock(); IIrbisConnection connection = mock.Object; BatchAccessor batch = new BatchAccessor(connection); int[] mfnList = { 1, 2, 3 }; MarcRecord[] records = batch.ReadRecords("IBIS", mfnList); Assert.AreEqual(3, records.Length); records = records.OrderBy(record => record.Mfn).ToArray(); Assert.AreEqual(1, records[0].Mfn); Assert.AreEqual(2, records[1].Mfn); Assert.AreEqual(3, records[2].Mfn); mock.Verify(c => c.ReadRecord(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>()), Times.Never); mock.Verify(c => c.ExecuteCommand(It.IsAny <AbstractCommand>()), Times.Once); }
public void should_update_when_component_pool_changes() { var mockTypeLookup = Substitute.For <IComponentTypeLookup>(); mockTypeLookup.GetComponentType(typeof(TestStructComponentOne)).Returns(0); mockTypeLookup.GetComponentType(typeof(TestStructComponentTwo)).Returns(1); var poolChanging1Subject = new Subject <bool>(); var mockComponentPool1 = Substitute.For <IComponentPool <TestStructComponentOne> >(); mockComponentPool1.OnPoolExtending.Returns(poolChanging1Subject); var poolChanging2Subject = new Subject <bool>(); var mockComponentPool2 = Substitute.For <IComponentPool <TestStructComponentTwo> >(); mockComponentPool2.OnPoolExtending.Returns(poolChanging2Subject); var mockComponentDatabase = Substitute.For <IComponentDatabase>(); mockComponentDatabase.GetPoolFor <TestStructComponentOne>(0).Returns(mockComponentPool1); mockComponentDatabase.GetPoolFor <TestStructComponentTwo>(1).Returns(mockComponentPool2); var mockObservableGroup = Substitute.For <IObservableGroup>(); mockObservableGroup.OnEntityAdded.Returns(Observable.Empty <IEntity>()); mockObservableGroup.OnEntityRemoving.Returns(Observable.Empty <IEntity>()); mockObservableGroup.OnEntityRemoved.Returns(Observable.Empty <IEntity>()); var mockBatchBuilder = Substitute.For <IBatchBuilder <TestStructComponentOne, TestStructComponentTwo> >(); var batchAccessor = new BatchAccessor <TestStructComponentOne, TestStructComponentTwo>(mockObservableGroup, mockComponentDatabase, mockBatchBuilder, mockTypeLookup); poolChanging1Subject.OnNext(false); poolChanging2Subject.OnNext(false); mockBatchBuilder.Received(3).Build(mockObservableGroup); }