Exemplo n.º 1
0
        public void TestThatQueryCallsMapOnFoodWasteObjectMapper()
        {
            var fixture = new Fixture();

            var translationInfoMock      = DomainObjectMockBuilder.BuildTranslationInfoMock();
            var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>();

            systemDataRepositoryMock.Stub(m => m.Get <ITranslationInfo>(Arg <Guid> .Is.Anything))
            .Return(translationInfoMock)
            .Repeat.Any();
            systemDataRepositoryMock.Stub(m => m.DataProviderForFoodGroupsGet())
            .Return(DomainObjectMockBuilder.BuildDataProviderMock())
            .Repeat.Any();
            systemDataRepositoryMock.Stub(m => m.FoodGroupGetAllOnRoot())
            .Return(DomainObjectMockBuilder.BuildFoodGroupMockCollection())
            .Repeat.Any();

            var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>();

            foodWasteObjectMapperMock.Stub(m => m.Map <IFoodGroupCollection, IView>(Arg <IFoodGroupCollection> .Is.Anything, Arg <CultureInfo> .Is.Anything))
            .Return(MockRepository.GenerateMock <IView>())
            .Repeat.Any();

            var foodGroupTreeGetQueryHandlerBase = new MyFoodGroupTreeGetQueryHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, fixture.Create <bool>());

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

            var foodGroupTreeGetQuery = fixture.Build <FoodGroupTreeGetQuery>()
                                        .With(m => m.TranslationInfoIdentifier, Guid.NewGuid())
                                        .Create();

            foodGroupTreeGetQueryHandlerBase.Query(foodGroupTreeGetQuery);

            foodWasteObjectMapperMock.AssertWasCalled(m => m.Map <IFoodGroupCollection, IView>(Arg <IFoodGroupCollection> .Is.NotNull, Arg <CultureInfo> .Is.Equal(translationInfoMock.CultureInfo)));
        }
Exemplo n.º 2
0
        public void TestThatQueryCallsMapWithFoodGroupCollectionContainingOnlyActiveFoodGroupsOnFoodWasteObjectMapperWhenOnlyActiveIsTrue()
        {
            var fixture = new Fixture();

            var dataProviderMock        = DomainObjectMockBuilder.BuildDataProviderMock();
            var foodGroupMockCollection = new List <IFoodGroup>
            {
                DomainObjectMockBuilder.BuildFoodGroupMock(dataProvider: dataProviderMock),
                DomainObjectMockBuilder.BuildFoodGroupMock(dataProvider: dataProviderMock),
                DomainObjectMockBuilder.BuildFoodGroupMock(dataProvider: dataProviderMock),
                DomainObjectMockBuilder.BuildFoodGroupMock(isActive: false, dataProvider: dataProviderMock),
                DomainObjectMockBuilder.BuildFoodGroupMock(isActive: false, dataProvider: dataProviderMock)
            };
            var systemDataRepositoryMock = MockRepository.GenerateMock <ISystemDataRepository>();

            systemDataRepositoryMock.Stub(m => m.Get <ITranslationInfo>(Arg <Guid> .Is.Anything))
            .Return(DomainObjectMockBuilder.BuildTranslationInfoMock())
            .Repeat.Any();
            systemDataRepositoryMock.Stub(m => m.DataProviderForFoodGroupsGet())
            .Return(dataProviderMock)
            .Repeat.Any();
            systemDataRepositoryMock.Stub(m => m.FoodGroupGetAllOnRoot())
            .Return(foodGroupMockCollection)
            .Repeat.Any();

            var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>();

            foodWasteObjectMapperMock.Stub(m => m.Map <IFoodGroupCollection, IView>(Arg <IFoodGroupCollection> .Is.NotNull, Arg <CultureInfo> .Is.Anything))
            .WhenCalled(e =>
            {
                var foodGroupCollection = (IFoodGroupCollection)e.Arguments.ElementAt(0);
                Assert.That(foodGroupCollection, Is.Not.Null);
                Assert.That(foodGroupCollection.Count, Is.EqualTo(foodGroupMockCollection.Count(foodGroup => foodGroup.IsActive)));
                foreach (var foodGroup in foodGroupCollection)
                {
                    Assert.That(foodGroup, Is.Not.Null);
                    Assert.That(foodGroup.IsActive, Is.True);
                    Assert.That(foodGroupMockCollection.Contains(foodGroup), Is.True);
                }
            })
            .Return(MockRepository.GenerateMock <IView>())
            .Repeat.Any();

            var foodGroupTreeGetQueryHandlerBase = new MyFoodGroupTreeGetQueryHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, true);

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

            var foodGroupTreeGetQuery = fixture.Build <FoodGroupTreeGetQuery>()
                                        .With(m => m.TranslationInfoIdentifier, Guid.NewGuid())
                                        .Create();

            foodGroupTreeGetQueryHandlerBase.Query(foodGroupTreeGetQuery);

            foodWasteObjectMapperMock.AssertWasCalled(m => m.Map <IFoodGroupCollection, IView>(Arg <IFoodGroupCollection> .Is.NotNull, Arg <CultureInfo> .Is.Anything));
        }
Exemplo n.º 3
0
        public void TestThatQueryThrowsArgumentNullExceptionWhenQueryIsNull()
        {
            var fixture = new Fixture();
            var systemDataRepositoryMock  = MockRepository.GenerateMock <ISystemDataRepository>();
            var foodWasteObjectMapperMock = MockRepository.GenerateMock <IFoodWasteObjectMapper>();

            var foodGroupTreeGetQueryHandlerBase = new MyFoodGroupTreeGetQueryHandler(systemDataRepositoryMock, foodWasteObjectMapperMock, fixture.Create <bool>());

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

            var exception = Assert.Throws <ArgumentNullException>(() => foodGroupTreeGetQueryHandlerBase.Query(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("query"));
            Assert.That(exception.InnerException, Is.Null);
        }