public void TestAtBrugerlisteGetBySystemAndInitialerKasterIntranetRepositoryExceptionHvisInitialerIkkeFindes()
        {
            var fixture = new Fixture();

            fixture.Customize <IBruger>(e => e.FromFactory(() =>
            {
                var brugerMock = MockRepository.GenerateMock <IBruger>();
                brugerMock.Stub(m => m.Initialer)
                .Return(fixture.Create <string>())
                .Repeat.Any();
                return(brugerMock);
            }));
            var fællesRepositoryMock = MockRepository.GenerateMock <IFællesRepository>();
            var objectMapperMock     = MockRepository.GenerateMock <IObjectMapper>();
            var exceptionBuilderMock = MockRepository.GenerateMock <IExceptionBuilder>();

            var systemMock = MockRepository.GenerateMock <ISystem>();

            systemMock.Stub(m => m.Nummer)
            .Return(fixture.Create <int>())
            .Repeat.Any();

            var brugere = fixture.CreateMany <IBruger>(7).ToList();
            var kalenderRepositoryMock = MockRepository.GenerateMock <IKalenderRepository>();

            kalenderRepositoryMock.Stub(m => m.BrugerGetAllBySystem(Arg <int> .Is.Equal(systemMock.Nummer)))
            .Return(brugere)
            .Repeat.Any();

            var commandHandler = new MyKalenderCommandHandler(kalenderRepositoryMock, fællesRepositoryMock, objectMapperMock, exceptionBuilderMock);

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

            var initialer = fixture.Create <string>();
            var exception = Assert.Throws <IntranetRepositoryException>(() => commandHandler.BrugerlisteGetBySystemAndInitialer(systemMock, initialer));

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Null);
            Assert.That(exception.Message, Is.Not.Empty);
            Assert.That(exception.Message, Is.EqualTo(Resource.GetExceptionMessage(ExceptionMessage.NoCalendarUserWithThoseInitials, initialer)));
            Assert.That(exception.InnerException, Is.Null);

            kalenderRepositoryMock.AssertWasCalled(m => m.BrugerGetAllBySystem(Arg <int> .Is.Equal(systemMock.Nummer)));
        }
        public void TestAtBrugerlisteGetBySystemAndInitialerKasterArgumentNullExceptionHvisInitialerErEmpty()
        {
            var kalenderRepositoryMock = MockRepository.GenerateMock <IKalenderRepository>();
            var fællesRepositoryMock   = MockRepository.GenerateMock <IFællesRepository>();
            var objectMapperMock       = MockRepository.GenerateMock <IObjectMapper>();
            var exceptionBuilderMock   = MockRepository.GenerateMock <IExceptionBuilder>();

            var commandHandler = new MyKalenderCommandHandler(kalenderRepositoryMock, fællesRepositoryMock, objectMapperMock, exceptionBuilderMock);

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

            var exception = Assert.Throws <ArgumentNullException>(() => commandHandler.BrugerlisteGetBySystemAndInitialer(MockRepository.GenerateMock <ISystem>(), string.Empty));

            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("initialer"));
            Assert.That(exception.InnerException, Is.Null);
        }
        public void TestAtBrugerlisteGetBySystemAndInitialerHenterBrugerlister()
        {
            var fixture = new Fixture();

            fixture.Customize <IBruger>(e => e.FromFactory(() =>
            {
                var brugerMock = MockRepository.GenerateMock <IBruger>();
                brugerMock.Stub(m => m.Initialer)
                .Return(fixture.Create <string>())
                .Repeat.Any();
                return(brugerMock);
            }));
            var fællesRepositoryMock = MockRepository.GenerateMock <IFællesRepository>();
            var objectMapperMock     = MockRepository.GenerateMock <IObjectMapper>();
            var exceptionBuilderMock = MockRepository.GenerateMock <IExceptionBuilder>();

            var systemMock = MockRepository.GenerateMock <ISystem>();

            systemMock.Stub(m => m.Nummer)
            .Return(fixture.Create <int>())
            .Repeat.Any();

            var brugere = fixture.CreateMany <IBruger>(7).ToList();
            var kalenderRepositoryMock = MockRepository.GenerateMock <IKalenderRepository>();

            kalenderRepositoryMock.Stub(m => m.BrugerGetAllBySystem(Arg <int> .Is.Equal(systemMock.Nummer)))
            .Return(brugere)
            .Repeat.Any();

            var commandHandler = new MyKalenderCommandHandler(kalenderRepositoryMock, fællesRepositoryMock, objectMapperMock, exceptionBuilderMock);

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

            var brugerliste = commandHandler.BrugerlisteGetBySystemAndInitialer(systemMock, brugere.ElementAt(1).Initialer);

            Assert.That(brugerliste, Is.Not.Null);
            Assert.That(brugerliste.Count(), Is.EqualTo(1));

            kalenderRepositoryMock.AssertWasCalled(m => m.BrugerGetAllBySystem(Arg <int> .Is.Equal(systemMock.Nummer)));
        }