Esempio n. 1
0
 public void Setup()
 {
     mapper = Substitute.For <ITwoWayMapper <string, int> >();
     mapper.Map(String1).Returns(Int1);
     mapper.Map(String2).Returns(Int2);
     mapper.Map(Int1).Returns(String1);
     mapper.Map(Int2).Returns(String2);
 }
 public void Setup()
 {
     mapper = Substitute.For<ITwoWayMapper<string, int>>();
     mapper.Map(String1).Returns(Int1);
     mapper.Map(String2).Returns(Int2);
     mapper.Map(Int1).Returns(String1);
     mapper.Map(Int2).Returns(String2);
 }
Esempio n. 3
0
        public UsersModule(IAppConfig appCfg, IUserRepository usersRepository,
                           ITwoWayMapper <User, UserModel> mapper)
            : base(appCfg, usersRepository, mapper, "/users")
        {
            Get("/login", args =>
            {
                if (this.Context.CurrentUser == null || !this.Context.CurrentUser.Identity.IsAuthenticated)
                {
                    return(Negotiate
                           .WithModel(new ModelWrapper <LoginModel> {
                        Error = new ModelWrapperError {
                            Message = "Login failed!"
                        }
                    })
                           .WithStatusCode(HttpStatusCode.Forbidden));
                }

                User user = this.Context.CurrentUser.Identity.AsUserIdentity().PersistentUser;

                // Login has it's own model!
                ModelWrapper <LoginModel> model = new ModelWrapper <LoginModel>
                {
                    Data = new LoginModel
                    {
                        Id    = user.Id,
                        Name  = user.Login,
                        Admin = true
                    }
                };

                return(Negotiate
                       .WithModel(model));
            });


            Put("/{id}/save", args =>
            {
                ModelWrapper <UserModel> model = this.Bind <ModelWrapper <UserModel> >();

                User entity = Mapper.Map(model.Data);

                if (!String.IsNullOrEmpty(model.Data.NewPassword))
                {
                    entity.PasswordData = usersRepository.HashPassword(model.Data.NewPassword);
                }

                return(Negotiate
                       .WithModel(new ModelWrapper <UserModel> {
                    Data = Mapper.Map(Repository.SaveEntity(entity))
                }));
            });
        }
Esempio n. 4
0
        public SessionsRepository(IMongoCollection <SessionDocument> collection,
                                  ITwoWayMapper <SessionDocument, Session> sessionMapper,
                                  ITwoWayMapper <TimelineEventDocument, TimelineEvent> eventsMapper,
                                  ITwoWayMapper <ReviewDocument, Review> reviewMapper)
        {
            this.collection    = collection;
            this.sessionMapper = sessionMapper;
            this.eventsMapper  = eventsMapper;
            this.reviewMapper  = reviewMapper;

            positiveInc = Builders <SessionDocument> .Update.Inc(x => x.Events[-1].Positive, 1);

            negativeInc = Builders <SessionDocument> .Update.Inc(x => x.Events[-1].Negative, 1);

            sessionInfoFields = Builders <SessionDocument> .Projection.Include(x => x.CreateDate)
                                .Include(x => x.Name)
                                .Include(x => x.Id);
        }
Esempio n. 5
0
 public EmployeeModule(IAppConfig appCfg, IEmployeeRepository employeesRepository,
                       ITwoWayMapper <Employee, EmployeeModel> mapper)
     : base(appCfg, employeesRepository, mapper, "/work/employees")
 {
 }
Esempio n. 6
0
 public RingModule(IAppConfig appCfg, IRingRepository ringRepository,
                   ITwoWayMapper <Ring, RingModel> mapper)
     : base(appCfg, ringRepository, mapper, "/skills/rings")
 {
 }
Esempio n. 7
0
 public SkillCategoryModule(IAppConfig appCfg, ISkillCategoryRepository skillCategoryRepository,
                            ITwoWayMapper <SkillCategory, SkillCategoryModel> mapper)
     : base(appCfg, skillCategoryRepository, mapper, "/skills/categories")
 {
 }
Esempio n. 8
0
 public SpotModule(IAppConfig appCfg, ISpotRepository spotRepository,
                   ITwoWayMapper <Spot, SpotModel> mapper)
     : base(appCfg, spotRepository, mapper, "/skills/spots")
 {
 }
Esempio n. 9
0
 public SectorModule(IAppConfig appCfg, ISectorRepository sectorRepository,
                     ITwoWayMapper <Sector, SectorModel> mapper)
     : base(appCfg, sectorRepository, mapper, "/skills/sectors")
 {
 }
Esempio n. 10
0
 public SessionMapper(ITwoWayMapper <TimelineEventDocument, TimelineEvent> eventMapper,
                      ITwoWayMapper <ReviewDocument, Review> reviewMapper)
 {
     this.eventMapper  = eventMapper;
     this.reviewMapper = reviewMapper;
 }
Esempio n. 11
0
 public static IReadOnlyCollection <TSource> Map <TSource, TDestination>(this ITwoWayMapper <TSource, TDestination> mapper, IEnumerable <TDestination> sourceCollection)
 {
     return(sourceCollection == null ? new List <TSource>(0) : sourceCollection.Select(mapper.Map).ToList());
 }
Esempio n. 12
0
 public SkillTypeModule(IAppConfig appCfg, ISkillTypeRepository skillTypeRepository,
                        ITwoWayMapper <SkillType, SkillTypeModel> mapper)
     : base(appCfg, skillTypeRepository, mapper, "/skills/types")
 {
 }
Esempio n. 13
0
        public BaseModule(
            IAppConfig appCfg,
            IRepository <E> repository,
            ITwoWayMapper <E, M> mapper,
            string modulePath = "")
            : base(appCfg.GetValue(@"BaseModulePath:Value") + modulePath)
        {
            // Authentication for all requests!
            this.RequiresAuthentication();

            // Authorisation for all requests!
            Before += ctx =>
            {
                Response response = new Nancy.Response();

                if (ctx.CurrentUser != null &&
                    !ctx.CurrentUser.HasClaim(ClaimTypes.System, typeof(E).Name + "_" + ctx.Request.Method))
                {
                    return(null);
                }

                return(response.WithStatusCode(HttpStatusCode.Forbidden));
            };

            Repository = repository;
            Mapper     = mapper;

            Get("/new", args =>
            {
                return(Negotiate
                       .WithModel(new ModelWrapper <M> {
                    Data = Mapper.Map(Repository.NewEntity())
                }));
            });

            Get("/{id}/get", args =>
            {
                return(Negotiate
                       .WithModel(new ModelWrapper <M> {
                    Data = Mapper.Map(Repository.GetEntity((int)args.id))
                }));
            });

            Get("/list", args =>
            {
                try
                {
                    return(Negotiate
                           .WithModel(new ModelWrapper <IList <M> > {
                        Data = (IList <M>)Mapper.Map(Repository.ListEntity())
                    }));
                }
                catch (Exception ex)
                {
                    return(Negotiate
                           .WithModel(new ModelWrapper <IList <M> > {
                        Error = new ModelWrapperError {
                            Message = ex.Message, Details = ex.StackTrace
                        }
                    }));
                }
            });


            Put("/{id}/save", args =>
            {
                ModelWrapper <M> model = this.Bind <ModelWrapper <M> >();

                E entity = Mapper.Map(model.Data);
                return(Negotiate
                       .WithModel(new ModelWrapper <M> {
                    Data = Mapper.Map(Repository.SaveEntity(entity))
                }));
            });


            Delete("/{id}/delete", args =>
            {
                return(Negotiate
                       .WithModel(new ModelWrapper <bool> {
                    Data = Repository.DeleteEntity((int)args.id)
                }));
            });
        }
Esempio n. 14
0
 public SkillModule(IAppConfig appCfg, ISkillRepository skillRepository,
                    ITwoWayMapper <Skill, SkillModel> mapper)
     : base(appCfg, skillRepository, mapper, "/skills/skills")
 {
 }