public void TestThatConstructorInitializePaymentWithPaymentReceipt()
        {
            var fixture          = new Fixture();
            var random           = new Random(fixture.Create <int>());
            var stakeholderMock  = DomainObjectMockBuilder.BuildStakeholderMock();
            var dataProviderMock = DomainObjectMockBuilder.BuildDataProviderMock(true);
            var paymentTime      = DateTime.Now.AddDays(random.Next(1, 7) * -1).AddMinutes(random.Next(120, 240));
            var paymentReference = fixture.Create <string>();
            var paymentReceipt   = fixture.CreateMany <byte>(random.Next(1024, 4096));

            var payment = new Payment(stakeholderMock, dataProviderMock, paymentTime, paymentReference, paymentReceipt);

            Assert.That(payment, Is.Not.Null);
            Assert.That(payment.Identifier, Is.Null);
            Assert.That(payment.Identifier.HasValue, Is.False);
            Assert.That(payment.Stakeholder, Is.Not.Null);
            Assert.That(payment.Stakeholder, Is.EqualTo(stakeholderMock));
            Assert.That(payment.DataProvider, Is.Not.Null);
            Assert.That(payment.DataProvider, Is.EqualTo(dataProviderMock));
            Assert.That(payment.PaymentTime, Is.EqualTo(paymentTime));
            Assert.That(payment.PaymentReference, Is.Not.Null);
            Assert.That(payment.PaymentReference, Is.Not.Empty);
            Assert.That(payment.PaymentReference, Is.EqualTo(paymentReference));
            Assert.That(payment.PaymentReceipt, Is.Not.Null);
            Assert.That(payment.PaymentReceipt, Is.Not.Empty);
            Assert.That(payment.PaymentReceipt, Is.EqualTo(paymentReceipt));
            Assert.That(payment.CreationTime, Is.EqualTo(DateTime.Now).Within(3).Seconds);
        }
Ejemplo n.º 2
0
        public void TestThatRemoveInactiveFoodItemsRemovesInactiveFoodItems()
        {
            var activeFoodItem1Mock = MockRepository.GenerateMock <IFoodItem>();

            activeFoodItem1Mock.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodItem2Mock = MockRepository.GenerateMock <IFoodItem>();

            activeFoodItem2Mock.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodItem3Mock = MockRepository.GenerateMock <IFoodItem>();

            activeFoodItem3Mock.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var inactiveFoodItem1Mock = MockRepository.GenerateMock <IFoodItem>();

            inactiveFoodItem1Mock.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodItem2Mock = MockRepository.GenerateMock <IFoodItem>();

            inactiveFoodItem2Mock.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodItem3Mock = MockRepository.GenerateMock <IFoodItem>();

            inactiveFoodItem3Mock.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();

            var dataProviderMock = DomainObjectMockBuilder.BuildDataProviderMock();

            var foodItemCollection = new FoodItemCollection(new List <IFoodItem> {
                activeFoodItem1Mock, inactiveFoodItem1Mock, activeFoodItem2Mock, inactiveFoodItem2Mock, activeFoodItem3Mock, inactiveFoodItem3Mock
            }, dataProviderMock);

            Assert.That(foodItemCollection, Is.Not.Null);
            Assert.That(foodItemCollection, Is.Not.Empty);
            Assert.That(foodItemCollection.Count, Is.EqualTo(6));
            Assert.That(foodItemCollection.Contains(activeFoodItem1Mock), Is.True);
            Assert.That(foodItemCollection.Contains(activeFoodItem2Mock), Is.True);
            Assert.That(foodItemCollection.Contains(activeFoodItem3Mock), Is.True);
            Assert.That(foodItemCollection.Contains(inactiveFoodItem1Mock), Is.True);
            Assert.That(foodItemCollection.Contains(inactiveFoodItem2Mock), Is.True);
            Assert.That(foodItemCollection.Contains(inactiveFoodItem3Mock), Is.True);

            foodItemCollection.RemoveInactiveFoodItems();
            Assert.That(foodItemCollection, Is.Not.Null);
            Assert.That(foodItemCollection, Is.Not.Empty);
            Assert.That(foodItemCollection.Count, Is.EqualTo(3));
            Assert.That(foodItemCollection.Contains(activeFoodItem1Mock), Is.True);
            Assert.That(foodItemCollection.Contains(activeFoodItem2Mock), Is.True);
            Assert.That(foodItemCollection.Contains(activeFoodItem3Mock), Is.True);
            Assert.That(foodItemCollection.Contains(inactiveFoodItem1Mock), Is.False);
            Assert.That(foodItemCollection.Contains(inactiveFoodItem2Mock), Is.False);
            Assert.That(foodItemCollection.Contains(inactiveFoodItem3Mock), Is.False);
        }
        public void TestThatConstructorInitializeForeignKey()
        {
            var fixture = new Fixture();

            var dataProviderMock        = DomainObjectMockBuilder.BuildDataProviderMock();
            var foreignKeyForIdentifier = Guid.NewGuid();
            var foreignKeyForType       = typeof(DataProvider);
            var foreignKeyValue         = fixture.Create <string>();
            var foreignKey = new ForeignKey(dataProviderMock, foreignKeyForIdentifier, foreignKeyForType, foreignKeyValue);

            Assert.That(foreignKey, Is.Not.Null);
            Assert.That(foreignKey.Identifier, Is.Null);
            Assert.That(foreignKey.Identifier.HasValue, Is.False);
            Assert.That(foreignKey.DataProvider, Is.Not.Null);
            Assert.That(foreignKey.DataProvider, Is.EqualTo(dataProviderMock));
            Assert.That(foreignKey.ForeignKeyForIdentifier, Is.EqualTo(foreignKeyForIdentifier));
            Assert.That(foreignKey.ForeignKeyForTypes, Is.Not.Null);
            Assert.That(foreignKey.ForeignKeyForTypes, Is.Not.Empty);
            Assert.That(foreignKey.ForeignKeyForTypes.Count(), Is.EqualTo(4));
            Assert.That(foreignKey.ForeignKeyForTypes.Contains(typeof(IDomainObject)), Is.True);
            Assert.That(foreignKey.ForeignKeyForTypes.Contains(typeof(IIdentifiable)), Is.True);
            Assert.That(foreignKey.ForeignKeyForTypes.Contains(typeof(ITranslatable)), Is.True);
            Assert.That(foreignKey.ForeignKeyForTypes.Contains(typeof(IDataProvider)), Is.True);
            Assert.That(foreignKey.ForeignKeyValue, Is.Not.Null);
            Assert.That(foreignKey.ForeignKeyValue, Is.Not.Empty);
            Assert.That(foreignKey.ForeignKeyValue, Is.EqualTo(foreignKeyValue));
        }
Ejemplo n.º 4
0
        public void TestThatRemoveInactiveFoodGroupsRemovesInactiveFoodGroups()
        {
            var activeFoodGroup1 = MockRepository.GenerateMock <IFoodGroup>();

            activeFoodGroup1.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodGroup2 = MockRepository.GenerateMock <IFoodGroup>();

            activeFoodGroup2.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodGroup3 = MockRepository.GenerateMock <IFoodGroup>();

            activeFoodGroup3.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var inactiveFoodGroup1 = MockRepository.GenerateMock <IFoodGroup>();

            inactiveFoodGroup1.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodGroup2 = MockRepository.GenerateMock <IFoodGroup>();

            inactiveFoodGroup2.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodGroup3 = MockRepository.GenerateMock <IFoodGroup>();

            inactiveFoodGroup3.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();

            var dataProviderMock = DomainObjectMockBuilder.BuildDataProviderMock();

            var foodGroupCollection = new FoodGroupCollection(new List <IFoodGroup> {
                activeFoodGroup1, inactiveFoodGroup1, activeFoodGroup2, inactiveFoodGroup2, activeFoodGroup3, inactiveFoodGroup3
            }, dataProviderMock);

            Assert.That(foodGroupCollection, Is.Not.Null);
            Assert.That(foodGroupCollection, Is.Not.Empty);
            Assert.That(foodGroupCollection.Count, Is.EqualTo(6));

            foodGroupCollection.RemoveInactiveFoodGroups();
            Assert.That(foodGroupCollection, Is.Not.Null);
            Assert.That(foodGroupCollection, Is.Not.Empty);
            Assert.That(foodGroupCollection.Count, Is.EqualTo(3));
            Assert.That(foodGroupCollection.Contains(activeFoodGroup1), Is.True);
            Assert.That(foodGroupCollection.Contains(activeFoodGroup2), Is.True);
            Assert.That(foodGroupCollection.Contains(activeFoodGroup3), Is.True);
        }
Ejemplo n.º 5
0
        public void TestThatConstructorInitializeFoodGroupCollection()
        {
            var foodGroupMockCollection = DomainObjectMockBuilder.BuildFoodGroupMockCollection().ToArray();
            var dataProviderMock        = DomainObjectMockBuilder.BuildDataProviderMock();

            var foodGroupCollection = new FoodGroupCollection(foodGroupMockCollection, dataProviderMock);

            Assert.That(foodGroupCollection, Is.Not.Null);
            Assert.That(foodGroupCollection.DataProvider, Is.Not.Null);
            Assert.That(foodGroupCollection.DataProvider, Is.EqualTo(dataProviderMock));
            foreach (var foodGroupMock in foodGroupMockCollection)
            {
                Assert.That(foodGroupCollection.Contains(foodGroupMock), Is.True);
            }
        }
Ejemplo n.º 6
0
        public void TestThatRemoveInactiveFoodGroupsDoesNotCallRemoveInactiveChildrenOnEachInactiveFoodGroup()
        {
            var activeFoodGroup1 = MockRepository.GenerateMock <IFoodGroup>();

            activeFoodGroup1.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodGroup2 = MockRepository.GenerateMock <IFoodGroup>();

            activeFoodGroup2.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodGroup3 = MockRepository.GenerateMock <IFoodGroup>();

            activeFoodGroup3.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var inactiveFoodGroup1 = MockRepository.GenerateMock <IFoodGroup>();

            inactiveFoodGroup1.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodGroup2 = MockRepository.GenerateMock <IFoodGroup>();

            inactiveFoodGroup2.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodGroup3 = MockRepository.GenerateMock <IFoodGroup>();

            inactiveFoodGroup3.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();

            var dataProviderMock = DomainObjectMockBuilder.BuildDataProviderMock();

            var foodGroupCollection = new FoodGroupCollection(new List <IFoodGroup> {
                activeFoodGroup1, inactiveFoodGroup1, activeFoodGroup2, inactiveFoodGroup2, activeFoodGroup3, inactiveFoodGroup3
            }, dataProviderMock);

            Assert.That(foodGroupCollection, Is.Not.Null);
            Assert.That(foodGroupCollection, Is.Not.Empty);

            foodGroupCollection.RemoveInactiveFoodGroups();

            inactiveFoodGroup1.AssertWasNotCalled(m => m.RemoveInactiveChildren());
            inactiveFoodGroup2.AssertWasNotCalled(m => m.RemoveInactiveChildren());
            inactiveFoodGroup3.AssertWasNotCalled(m => m.RemoveInactiveChildren());
        }
Ejemplo n.º 7
0
        public void TestThatRemoveInactiveFoodItemsDoesNotCallRemoveInactiveFoodGroupsOnEachInactiveFoodItem()
        {
            var activeFoodItem1Mock = MockRepository.GenerateMock <IFoodItem>();

            activeFoodItem1Mock.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodItem2Mock = MockRepository.GenerateMock <IFoodItem>();

            activeFoodItem2Mock.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var activeFoodItem3Mock = MockRepository.GenerateMock <IFoodItem>();

            activeFoodItem3Mock.Stub(m => m.IsActive)
            .Return(true)
            .Repeat.Any();
            var inactiveFoodItem1Mock = MockRepository.GenerateMock <IFoodItem>();

            inactiveFoodItem1Mock.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodItem2Mock = MockRepository.GenerateMock <IFoodItem>();

            inactiveFoodItem2Mock.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();
            var inactiveFoodItem3Mock = MockRepository.GenerateMock <IFoodItem>();

            inactiveFoodItem3Mock.Stub(m => m.IsActive)
            .Return(false)
            .Repeat.Any();

            var dataProviderMock = DomainObjectMockBuilder.BuildDataProviderMock();

            var foodItemCollection = new FoodItemCollection(new List <IFoodItem> {
                activeFoodItem1Mock, inactiveFoodItem1Mock, activeFoodItem2Mock, inactiveFoodItem2Mock, activeFoodItem3Mock, inactiveFoodItem3Mock
            }, dataProviderMock);

            Assert.That(foodItemCollection, Is.Not.Null);
            Assert.That(foodItemCollection, Is.Not.Empty);

            foodItemCollection.RemoveInactiveFoodItems();

            inactiveFoodItem1Mock.AssertWasNotCalled(m => m.RemoveInactiveFoodGroups());
            inactiveFoodItem2Mock.AssertWasNotCalled(m => m.RemoveInactiveFoodGroups());
            inactiveFoodItem3Mock.AssertWasNotCalled(m => m.RemoveInactiveFoodGroups());
        }
        public void TestThatForeignKeyValueSetterThrowsArgumentNullExceptionWhenForeignKeyValueIsInvalid(string invalidValue)
        {
            var fixture = new Fixture();

            var foreignKey = new ForeignKey(DomainObjectMockBuilder.BuildDataProviderMock(), Guid.NewGuid(), typeof(DataProvider), fixture.Create <string>());

            Assert.That(foreignKey, Is.Not.Null);

            var exception = Assert.Throws <ArgumentNullException>(() => foreignKey.ForeignKeyValue = invalidValue);

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("value"));
            Assert.That(exception.InnerException, Is.Null);
        }
        public void TestThatTranslateCallsTranslateOnDataProvider()
        {
            var fixture          = new Fixture();
            var random           = new Random(fixture.Create <int>());
            var dataProviderMock = DomainObjectMockBuilder.BuildDataProviderMock(true);

            var payment = new MyPayment(DomainObjectMockBuilder.BuildStakeholderMock(), dataProviderMock, DateTime.Now.AddDays(random.Next(1, 7) * -1).AddMinutes(random.Next(120, 240)), fixture.Create <string>());

            Assert.That(payment, Is.Not.Null);
            Assert.That(payment.DataProvider, Is.Not.Null);
            Assert.That(payment.DataProvider, Is.EqualTo(dataProviderMock));

            var translationCulture = CultureInfo.CurrentCulture;

            payment.Translate(translationCulture);

            dataProviderMock.AssertWasCalled(m => m.Translate(Arg <CultureInfo> .Is.Equal(translationCulture)));
        }
        public void TestThatForeignKeyValueSetterUpdatesValue()
        {
            var fixture = new Fixture();

            var foreignKey = new ForeignKey(DomainObjectMockBuilder.BuildDataProviderMock(), Guid.NewGuid(), typeof(DataProvider), fixture.Create <string>());

            Assert.That(foreignKey, Is.Not.Null);

            var newValue = fixture.Create <string>();

            Assert.That(foreignKey.ForeignKeyValue, Is.Not.Null);
            Assert.That(foreignKey.ForeignKeyValue, Is.Not.Empty);
            Assert.That(foreignKey.ForeignKeyValue, Is.Not.EqualTo(newValue));

            foreignKey.ForeignKeyValue = newValue;
            Assert.That(foreignKey.ForeignKeyValue, Is.Not.Null);
            Assert.That(foreignKey.ForeignKeyValue, Is.Not.Empty);
            Assert.That(foreignKey.ForeignKeyValue, Is.EqualTo(newValue));
        }
        public void TestThatDataProviderSetterChangeValue()
        {
            var fixture = new Fixture();
            var random  = new Random(fixture.Create <int>());

            var payment = new MyPayment(DomainObjectMockBuilder.BuildStakeholderMock(), DomainObjectMockBuilder.BuildDataProviderMock(true), DateTime.Now.AddDays(random.Next(1, 7) * -1).AddMinutes(random.Next(120, 240)), fixture.Create <string>());

            Assert.That(payment, Is.Not.Null);
            Assert.That(payment.DataProvider, Is.Not.Null);

            var newDataProvider = DomainObjectMockBuilder.BuildDataProviderMock(true);

            Assert.That(newDataProvider, Is.Not.Null);
            Assert.That(newDataProvider, Is.Not.EqualTo(payment.DataProvider));

            payment.DataProvider = newDataProvider;
            Assert.That(payment.DataProvider, Is.Not.Null);
            Assert.That(payment.DataProvider, Is.EqualTo(newDataProvider));
        }
        public void TestThatTranslateThrowsArgumentNullExceptionWhenTranslationCultureIsNull()
        {
            var fixture = new Fixture();
            var random  = new Random(fixture.Create <int>());

            var payment = new MyPayment(DomainObjectMockBuilder.BuildStakeholderMock(), DomainObjectMockBuilder.BuildDataProviderMock(true), DateTime.Now.AddDays(random.Next(1, 7) * -1).AddMinutes(random.Next(120, 240)), fixture.Create <string>());

            Assert.That(payment, Is.Not.Null);

            var exception = Assert.Throws <ArgumentNullException>(() => payment.Translate(null));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("translationCulture"));
            Assert.That(exception.InnerException, Is.Null);
        }
        public void TestThatPaymentReceiptSetterChangeValueToNull()
        {
            var fixture = new Fixture();
            var random  = new Random(fixture.Create <int>());

            var payment = new MyPayment(DomainObjectMockBuilder.BuildStakeholderMock(), DomainObjectMockBuilder.BuildDataProviderMock(true), DateTime.Now.AddDays(random.Next(1, 7) * -1).AddMinutes(random.Next(120, 240)), fixture.Create <string>(), fixture.CreateMany <byte>(random.Next(1024, 4096)).ToArray());

            Assert.That(payment, Is.Not.Null);
            Assert.That(payment.PaymentReceipt, Is.Not.Null);
            Assert.That(payment.PaymentReceipt, Is.Not.Empty);

            payment.PaymentReceipt = null;
            Assert.That(payment.PaymentReceipt, Is.Null);
        }
        public void TestThatConstructorThrowsArgumentNullExceptionWhenPaymentReferenceIsInvalid(string invalidValue)
        {
            var fixture = new Fixture();
            var random  = new Random(fixture.Create <int>());

            var exception = Assert.Throws <ArgumentNullException>(() => new Payment(DomainObjectMockBuilder.BuildStakeholderMock(), DomainObjectMockBuilder.BuildDataProviderMock(true), DateTime.Now.AddDays(random.Next(1, 7) * -1).AddMinutes(random.Next(120, 240)), invalidValue));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("paymentReference"));
            Assert.That(exception.InnerException, Is.Null);
        }
        public void TestThatConstructorThrowsArgumentNullExceptionWhenForeignKeyForTypeIsNull()
        {
            var fixture = new Fixture();

            var exception = Assert.Throws <ArgumentNullException>(() => new ForeignKey(DomainObjectMockBuilder.BuildDataProviderMock(), Guid.NewGuid(), null, fixture.Create <string>()));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("foreignKeyForType"));
            Assert.That(exception.InnerException, Is.Null);
        }
        public void TestThatConstructorThrowsArgumentNullExceptionWhenForeignKeyValueIsInvalid(string invalidValue)
        {
            var exception = Assert.Throws <ArgumentNullException>(() => new ForeignKey(DomainObjectMockBuilder.BuildDataProviderMock(), Guid.NewGuid(), typeof(DataProvider), invalidValue));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("foreignKeyValue"));
            Assert.That(exception.InnerException, Is.Null);
        }
Ejemplo n.º 17
0
        public void TestThatConstructorThrowsArgumentNullExceptionWhenFoodGroupsIsNull()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => new FoodGroupCollection(null, DomainObjectMockBuilder.BuildDataProviderMock()));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Null);
            Assert.That(exception.ParamName, Is.Not.Empty);
            Assert.That(exception.ParamName, Is.EqualTo("source"));
            Assert.That(exception.InnerException, Is.Null);
        }