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); }
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)) })); }); }
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); }
public EmployeeModule(IAppConfig appCfg, IEmployeeRepository employeesRepository, ITwoWayMapper <Employee, EmployeeModel> mapper) : base(appCfg, employeesRepository, mapper, "/work/employees") { }
public RingModule(IAppConfig appCfg, IRingRepository ringRepository, ITwoWayMapper <Ring, RingModel> mapper) : base(appCfg, ringRepository, mapper, "/skills/rings") { }
public SkillCategoryModule(IAppConfig appCfg, ISkillCategoryRepository skillCategoryRepository, ITwoWayMapper <SkillCategory, SkillCategoryModel> mapper) : base(appCfg, skillCategoryRepository, mapper, "/skills/categories") { }
public SpotModule(IAppConfig appCfg, ISpotRepository spotRepository, ITwoWayMapper <Spot, SpotModel> mapper) : base(appCfg, spotRepository, mapper, "/skills/spots") { }
public SectorModule(IAppConfig appCfg, ISectorRepository sectorRepository, ITwoWayMapper <Sector, SectorModel> mapper) : base(appCfg, sectorRepository, mapper, "/skills/sectors") { }
public SessionMapper(ITwoWayMapper <TimelineEventDocument, TimelineEvent> eventMapper, ITwoWayMapper <ReviewDocument, Review> reviewMapper) { this.eventMapper = eventMapper; this.reviewMapper = reviewMapper; }
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()); }
public SkillTypeModule(IAppConfig appCfg, ISkillTypeRepository skillTypeRepository, ITwoWayMapper <SkillType, SkillTypeModel> mapper) : base(appCfg, skillTypeRepository, mapper, "/skills/types") { }
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) })); }); }
public SkillModule(IAppConfig appCfg, ISkillRepository skillRepository, ITwoWayMapper <Skill, SkillModel> mapper) : base(appCfg, skillRepository, mapper, "/skills/skills") { }