Beispiel #1
0
        public IFrequentlyAskedQuestionService CreateEventManagement()
        {
            var eventManagementMock = new Mock <IFrequentlyAskedQuestionService>();

            eventManagementMock.Setup(ams => ams.GetAll())
            .Returns(() => {
                return(Task.FromResult(new List <PersistenceWrapper <FrequentlyAskedQuestion> >(MockDataGenerator.FrequentlyAskedQuestions).AsEnumerable()));
            });

            eventManagementMock.Setup(ams => ams.Create(It.IsAny <FrequentlyAskedQuestion>())).Returns((FrequentlyAskedQuestion a) =>
            {
                var output    = _mapper.Map <FrequentlyAskedQuestion, PersistenceWrapper <FrequentlyAskedQuestion> >(a);
                output.Common = MockDataGenerator.CreateCommon();
                MockDataGenerator.FrequentlyAskedQuestions.Add(output);
                return(Task.FromResult(true));
            });

            eventManagementMock.Setup(ams => ams.Update(It.IsAny <FrequentlyAskedQuestion>())).Returns((FrequentlyAskedQuestion a) =>
            {
                MockDataGenerator.FrequentlyAskedQuestions.ForEach(ap =>
                {
                    if (ap.Model.Id == a.Id)
                    {
                        _mapper.Map <FrequentlyAskedQuestion, PersistenceWrapper <FrequentlyAskedQuestion> >(a, ap);
                        ap.Common.UpdatedOn = DateTimeOffset.UtcNow;
                    }
                });
                return(Task.FromResult(true));
            });

            eventManagementMock.Setup(ams => ams.UploadFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Func <Stream, Task> >())).Returns(async(string n, string ct, Func <Stream, Task> f) =>
            {
                Guid id      = Guid.NewGuid();
                var fileName = Path.GetTempFileName();
                Console.WriteLine(fileName);

                using (var file = File.Create(fileName))
                {
                    await f(file);
                }
                return(fileName);
            });

            eventManagementMock.Setup(ams => ams.Delete(It.IsAny <Guid>())).Returns((Guid id) =>
            {
                MockDataGenerator.FrequentlyAskedQuestions.RemoveAll(ap => ap.Model.Id == id);
                return(Task.FromResult(true));
            });

            return(eventManagementMock.Object);
        }
Beispiel #2
0
        public IEventManagementService CreateEventManagement()
        {
            var eventManagementMock = new Mock <IEventManagementService>();

            eventManagementMock.Setup(ams => ams.GetAll())
            .Returns(() => {
                return(Task.FromResult(new List <Event>(MockDataGenerator.Events).AsEnumerable()));
            });

            eventManagementMock.Setup(ams => ams.Create(It.IsAny <Event>())).Returns((Event a) =>
            {
                a.Common = MockDataGenerator.CreateCommon();
                MockDataGenerator.Events.Add(a);
                return(Task.FromResult(true));
            });

            eventManagementMock.Setup(ams => ams.Update(It.IsAny <Event>())).Returns((Event a) =>
            {
                MockDataGenerator.Events.ForEach(ap =>
                {
                    if (ap.Id == a.Id)
                    {
                        ap.Active            = a.Active;
                        ap.Name              = a.Name;
                        ap.AnnualMaximum     = a.AnnualMaximum;
                        ap.Points            = a.Points;
                        ap.RequireAttachment = a.RequireAttachment;
                    }
                });
                return(Task.FromResult(true));
            });

            eventManagementMock.Setup(ams => ams.Disable(It.IsAny <Guid>())).Returns((Guid id) =>
            {
                MockDataGenerator.Events.ForEach(ap =>
                {
                    if (ap.Id == id)
                    {
                        ap.Active = false;
                    }
                });
                return(Task.FromResult(true));
            });

            return(eventManagementMock.Object);
        }
Beispiel #3
0
        public IActivityManagementService CreateActivityManagement()
        {
            var activityManagementMock = new Mock <IActivityManagementService>();

            activityManagementMock.Setup(ams => ams.GetAll())
            .Returns(() =>
            {
                return(Task.FromResult(new List <Activity>(MockDataGenerator.Activities).AsEnumerable()));
            });

            activityManagementMock.Setup(ams => ams.Create(It.IsAny <Activity>())).Returns((Activity a) =>
            {
                a.Common = MockDataGenerator.CreateCommon();
                MockDataGenerator.Activities.Add(a);
                return(Task.FromResult(true));
            });

            activityManagementMock.Setup(ams => ams.Update(It.IsAny <Activity>())).Returns((Activity a) =>
            {
                MockDataGenerator.Activities.ForEach(ap =>
                {
                    if (ap.Id == a.Id)
                    {
                        ap.Active = a.Active;
                        ap.Name   = a.Name;
                    }
                });
                return(Task.FromResult(true));
            });

            activityManagementMock.Setup(ams => ams.Disable(It.IsAny <Guid>())).Returns((Guid id) =>
            {
                MockDataGenerator.Activities.ForEach(ap =>
                {
                    if (ap.Id == id)
                    {
                        ap.Active = false;
                    }
                });
                return(Task.FromResult(true));
            });

            return(activityManagementMock.Object);
        }
Beispiel #4
0
        public IEventParticipationService CreateEventParticipation()
        {
            var eventParticipationMock = new Mock <IEventParticipationService>();

            eventParticipationMock.Setup(ams => ams.GetByRelativeMonthIndex(It.IsAny <int>(), It.IsAny <Guid>()))
            .Returns((int i, Guid id) =>
            {
                var relativeDate = DateTimeOffset.UtcNow.AddMonths(i);
                var filtered     = MockDataGenerator.EventParticipations.Where(i => i.Model.SubmissionDate.Year == relativeDate.Year && i.Model.SubmissionDate.Month == relativeDate.Month);
                return(Task.FromResult(new List <PersistenceWrapper <EventParticipation> >(filtered).AsEnumerable()));
            });

            eventParticipationMock.Setup(ams => ams.Create(It.IsAny <EventParticipation>())).Returns((EventParticipation ap) =>
            {
                var model    = _mapper.Map <EventParticipation, PersistenceWrapper <EventParticipation> >(ap);
                model.Common = MockDataGenerator.CreateCommon();
                MockDataGenerator.EventParticipations.Add(model);
                return(Task.FromResult(true));
            });

            eventParticipationMock.Setup(ams => ams.UploadFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Func <Stream, Task> >())).Returns(async(string n, string ct, Func <Stream, Task> f) =>
            {
                Guid id      = Guid.NewGuid();
                var fileName = Path.GetTempFileName();
                Console.WriteLine(fileName);

                using (var file = File.Create(fileName))
                {
                    await f(file);
                }
                return(fileName);
            });

            eventParticipationMock.Setup(ams => ams.Delete(It.IsAny <Guid>())).Returns((Guid id) =>
            {
                MockDataGenerator.EventParticipations.RemoveAll(ap => ap.Model.Id == id);
                return(Task.FromResult(true));
            });

            return(eventParticipationMock.Object);
        }
        public IActivityParticipationService CreateActivityParticipation()
        {
            var activityParticipationMock = new Mock <IActivityParticipationService>();

            activityParticipationMock.Setup(ams => ams.GetByRelativeMonthIndex(It.IsAny <int>(), It.IsAny <Guid>()))
            .Returns((int i, Guid id) => Task.FromResult(new List <PersistenceWrapper <ActivityParticipation> >(GetByRelativeIndex(i)).AsEnumerable()));

            activityParticipationMock.Setup(ams => ams.Create(It.IsAny <ActivityParticipation>())).Returns((ActivityParticipation ap) =>
            {
                var model    = _mapper.Map <ActivityParticipation, PersistenceWrapper <ActivityParticipation> >(ap);
                model.Common = MockDataGenerator.CreateCommon();
                MockDataGenerator.ActivityParticipations.Add(model);
                return(Task.FromResult(true));
            });

            activityParticipationMock.Setup(ams => ams.Delete(It.IsAny <Guid>())).Returns((Guid id) =>
            {
                MockDataGenerator.ActivityParticipations.RemoveAll(ap => ap.Model.Id == id);
                return(Task.FromResult(true));
            });
            return(activityParticipationMock.Object);
        }