예제 #1
0
        public void TestThatQueryReturnResultFromMapOnFoodWasteObjectMapper()
        {
            var fixture = new Fixture();

            var translationInfoMockCollection = DomainObjectMockBuilder.BuildTranslationInfoMockCollection().ToList();
            var systemDataRepository          = MockRepository.GenerateMock <ISystemDataRepository>();

            systemDataRepository.Stub(m => m.TranslationInfoGetAll())
            .Return(translationInfoMockCollection)
            .Repeat.Any();

            var translationInfoSystemViewCollection = fixture.CreateMany <TranslationInfoSystemView>(translationInfoMockCollection.Count).ToList();
            var foodWasteObjectMapper = MockRepository.GenerateMock <IFoodWasteObjectMapper>();

            foodWasteObjectMapper.Stub(m => m.Map <IEnumerable <ITranslationInfo>, IEnumerable <TranslationInfoSystemView> >(Arg <IEnumerable <ITranslationInfo> > .Is.NotNull, Arg <CultureInfo> .Is.Anything))
            .Return(translationInfoSystemViewCollection)
            .Repeat.Any();

            var translationInfoCollectionGetQueryHandler = new TranslationInfoCollectionGetQueryHandler(systemDataRepository, foodWasteObjectMapper);

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

            var result = translationInfoCollectionGetQueryHandler.Query(fixture.Create <TranslationInfoCollectionGetQuery>());

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.EqualTo(translationInfoSystemViewCollection));
        }
예제 #2
0
        public void TestThatQueryCallsMapOnFoodWasteObjectMapper()
        {
            var fixture = new Fixture();

            var translationInfoMockCollection = DomainObjectMockBuilder.BuildTranslationInfoMockCollection().ToList();
            var systemDataRepository          = MockRepository.GenerateMock <ISystemDataRepository>();

            systemDataRepository.Stub(m => m.TranslationInfoGetAll())
            .Return(translationInfoMockCollection)
            .Repeat.Any();

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

            foodWasteObjectMapper.Stub(m => m.Map <IEnumerable <ITranslationInfo>, IEnumerable <TranslationInfoSystemView> >(Arg <IEnumerable <ITranslationInfo> > .Is.NotNull, Arg <CultureInfo> .Is.Anything))
            .WhenCalled(e => ((IEnumerable <ITranslationInfo>)e.Arguments.ElementAt(0)).ToList().ForEach(n => Assert.IsTrue(translationInfoMockCollection.Contains(n))))
            .Return(fixture.CreateMany <TranslationInfoSystemView>(translationInfoMockCollection.Count).ToList())
            .Repeat.Any();

            var translationInfoCollectionGetQueryHandler = new TranslationInfoCollectionGetQueryHandler(systemDataRepository, foodWasteObjectMapper);

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

            translationInfoCollectionGetQueryHandler.Query(fixture.Create <TranslationInfoCollectionGetQuery>());

            foodWasteObjectMapper.AssertWasCalled(m => m.Map <IEnumerable <ITranslationInfo>, IEnumerable <TranslationInfoSystemView> >(Arg <IEnumerable <ITranslationInfo> > .Is.NotNull, Arg <CultureInfo> .Is.Null));
        }
예제 #3
0
        public void TestThatConstructorInitializeTranslationInfoCollectionGetQueryHandler()
        {
            var fixture = new Fixture();

            fixture.Customize <ISystemDataRepository>(e => e.FromFactory(() => MockRepository.GenerateMock <ISystemDataRepository>()));
            fixture.Customize <IFoodWasteObjectMapper>(e => e.FromFactory(() => MockRepository.GenerateMock <IFoodWasteObjectMapper>()));

            var translationInfoCollectionGetQueryHandler = new TranslationInfoCollectionGetQueryHandler(fixture.Create <ISystemDataRepository>(), fixture.Create <IFoodWasteObjectMapper>());

            Assert.That(translationInfoCollectionGetQueryHandler, Is.Not.Null);
        }
예제 #4
0
        public void TestThatQueryThrowsArgumentNullExceptionIfTranslationInfoCollectionGetQueryIsNull()
        {
            var fixture = new Fixture();

            fixture.Customize <ISystemDataRepository>(e => e.FromFactory(() => MockRepository.GenerateMock <ISystemDataRepository>()));
            fixture.Customize <IFoodWasteObjectMapper>(e => e.FromFactory(() => MockRepository.GenerateMock <IFoodWasteObjectMapper>()));

            var translationInfoCollectionGetQueryHandler = new TranslationInfoCollectionGetQueryHandler(fixture.Create <ISystemDataRepository>(), fixture.Create <IFoodWasteObjectMapper>());

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

            var exception = Assert.Throws <ArgumentNullException>(() => translationInfoCollectionGetQueryHandler.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);
        }