public When_mapping_int_as_string_and_long_as_long()
        {
            var dynamicObjectMapper = new CustomMapper();

            dynamicObjectWithInt = dynamicObjectMapper.MapObject(123);
            dynamicObjectWithLong = dynamicObjectMapper.MapObject(456L);
        }
        public When_mapping_reducing_property_set_for_seriable_type()
        {
            var dynamicObjectMapper = new CustomMapper();

            dynamicObject = dynamicObjectMapper.MapObject(new DataObject
            {
                PropertyOne = "one",
                PropertyTwo = "two"
            });
        }
        public When_converting_to_object_with_abstract_properties_in_absence_of_type_information()
        {
            dynamicObject = new DynamicObject()
            {
                { "Ref", new DynamicObject() },
                { "Value1", "the value's pay load" },
                { "Value2", 222 },
                { "Value3", null },
                { "Value4", new DynamicObject() },
            };

            var mapper = new CustomMapper();

            obj = mapper.Map<ClassWithAbstractProperties>(dynamicObject);
        }
예제 #4
0
        public ActionResult Index(int page = 1)
        {
            IEnumerable<BankAccountViewModel> bankAccounts = CustomMapper<BankAccountDTO, BankAccountViewModel>.Map(_service.GetAll());

            PageViewModel<BankAccountViewModel> pvm = new PageViewModel<BankAccountViewModel>
            {
                Items = bankAccounts.OrderBy(b => b.Id).Skip((page - 1) * PAGE_SIZE).Take(PAGE_SIZE),
                PagingInfo = new PagingInfo
                {
                    CurrentPage = page,
                    ItemsPerPage = PAGE_SIZE,
                    TotalItems = bankAccounts.Count()
                }
            };

            return View(pvm);
        }
예제 #5
0
        public static ConsumerMedicaidNumberModel CreateOrUpdate(RayimContext context, ConsumerMedicaidNumberModel model)
        {
            var dbEntity = context.ConsumerMedicaidNumbers.FirstOrDefault(x => x.Id == model.Id);

            if (dbEntity == null)
            {
                var map = CustomMapper.MapEntity <ConsumerMedicaidNumber>(model);
                dbEntity = context.ConsumerMedicaidNumbers.Add(map);
            }
            else
            {
                CustomMapper.MapEntity <ConsumerMedicaidNumber>(model, dbEntity);
            }
            context.SaveChanges();

            return(CustomMapper.MapEntity <ConsumerMedicaidNumberModel>(dbEntity));
        }
예제 #6
0
        public ConsumerEmployee GetModel()
        {
            ConsumerEmployee model = new ConsumerEmployee();

            CustomMapper.MapEntity(this, model);

            if (this.ConsumerEmployeeId.HasValue)
            {
                model.ConsumerEmployeeId = this.ConsumerEmployeeId.Value;
            }
            else
            {
                model.ConsumerEmployeeId = 0;
            }

            return(model);
        }
예제 #7
0
        private List <HistoryMessage> CreateMessagesForAddCardsPerPlayer(GamePlayer gamePlayer)
        {
            var historyMessages = new List <HistoryMessage>();

            foreach (PlayerCard playerCard in gamePlayer.PlayerCards)
            {
                string playerType = gamePlayer.Player.Type.ToString();
                string cardName   = playerCard.Card.ToString();
                string message    = $@"Card(Id={playerCard.Card.Id}, Value={playerCard.Card.Worth}, Name={cardName}) is added to 
                             {playerType}(Id={gamePlayer.Player.Id}, Name={gamePlayer.Player.Name})";

                HistoryMessage historyMessage = CustomMapper.MapHistoryMessage(gamePlayer.GameId, message);
                historyMessages.Add(historyMessage);
            }

            return(historyMessages);
        }
예제 #8
0
        private async Task DistributeEndCardsForDealer(GamePlayer dealer)
        {
            var         createdPlayerCards = new List <PlayerCard>();
            List <Card> deck = await _cardRepository.GetSpecifiedAmount(CardValue.AmountOfEndCardsForDealer);

            for (int iterator = deck.Count(); iterator > 0 && dealer.CardScore < CardValue.MaxDealerCardScore; iterator--)
            {
                Card       card = PopCardsFromDeck(deck, CardValue.OneCard).First();
                PlayerCard createdPlayerCard = CustomMapper.MapPlayerCard(dealer, card);
                dealer.PlayerCards.Add(createdPlayerCard);
                createdPlayerCards.Add(createdPlayerCard);
                dealer.CardScore = CountCardScore(dealer.PlayerCards);
            }

            await _gamePlayerRepository.Update(dealer);

            await _playerCardRepository.CreateMany(createdPlayerCards);
        }
        public When_converting_to_object_with_abstract_properties_in_absence_of_type_information()
        {
            dynamicObject = new DynamicObject()
            {
                Properties = new PropertySet
                {
                    { "Ref", new DynamicObject() },
                    { "Value1", "the value's pay load" },
                    { "Value2", 222 },
                    { "Value3", null },
                    { "Value4", new DynamicObject() },
                },
            };

            var mapper = new CustomMapper();

            obj = mapper.Map <ClassWithAbstractProperties>(dynamicObject);
        }
        public void Delete_InvalidID_ReturnsNotFoundResult()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper            _customMapper  = new CustomMapper(context);
                IDataRepository <Recipe> mockRepository = new RecipeManager(context);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                //Act
                var notFoundResult = recipecontroller.Delete(68);

                // Assert
                Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
            }
        }
        public void UpdSummary(string user, SummaryBLL summ)
        {
            if (summ == null)
            {
                throw new NullSummaryException();
            }
            var currUser = uow.UsersRepository.Get().FirstOrDefault(c => c.Login == user);

            if (currUser == null)
            {
                throw new NoSuchUserException();
            }
            if (currUser != null)
            {
                currUser.UserSummary = CustomMapper.getSummary(summ);
            }
            uow.Save();
        }
예제 #12
0
        public static ConsumerAddressModel CreateOrUpdate(RayimContext context, BaseConsumerAddressModel inputModel)
        {
            var isNew    = inputModel.Id == 0;
            var dbEntity = context.ConsumerAddresses.FirstOrDefault(x => x.Id == inputModel.Id);

            if (dbEntity == null)
            {
                dbEntity = context.ConsumerAddresses.Add(CustomMapper.MapEntity <ConsumerAddress>(inputModel));
            }
            else
            {
                CustomMapper.MapEntity <ConsumerAddress>(inputModel, dbEntity);
            }
            context.SaveChanges();


            return(CustomMapper.MapEntity <ConsumerAddressModel>(dbEntity));
        }
예제 #13
0
        public int UpdateOrder(Order_x order)//-----------------------------------------------propaply not working 
        {
            int result = -1;
            using (var context = new PetSitterDbContext())
            {
                var freshOrder = MapToDamain(order);
                var curOrder = context.Orders.Where(x => x.Id == order.Id).FirstOrDefault();
                CustomMapper.Map<Order, Order>(freshOrder, curOrder);
                //context.Sitters.Where(x=> x.Id == order.Sitter.Id).First().Orders.

                //update order in users and sitters!!!

                context.SaveChanges();
                result = 0;
            }

            return result;
        }
예제 #14
0
        public static Task <DtResult <TResult> > GetResultDatatablesAsync <TResult, TEntity>(IQueryable <TEntity> query,
                                                                                             string search, int?draw, string sortOrder, int?start, int?length, List <string> columnFilters) where TResult : BaseDto where TEntity : BaseEntity
        {
            try
            {
                //var mapper = DependencyResolver.Current.GetService<IMapper>();
                IMapper mapper = new CustomMapper();

                var filter = FilterResult(search, query, columnFilters);

                //var count = filter.CountAsync().Result;
                var count = filter.Count();

                if (sortOrder.StartsWith("String", StringComparison.Ordinal))
                {
                    sortOrder = sortOrder.Replace("String", "");
                }
                var type = typeof(TEntity).GetTypeInfo().GetProperties().FirstOrDefault(a => sortOrder.StartsWith(a.Name, StringComparison.Ordinal));

                //var resultFilter = type != null ? filter.SortBy(sortOrder)
                //.Skip(start ?? 0)
                //.Take(length ?? 0).ToListAsync().Result : Activator.CreateInstance(typeof(List<>).MakeGenericType(typeof(TResult)));

                var resultFilter = type != null?filter.OrderBy(a => sortOrder)
                                   .Skip(start ?? 0)
                                   .Take(length ?? 0) : Activator.CreateInstance(typeof(List <>).MakeGenericType(typeof(TResult)));


                var result = new DtResult <TResult>
                {
                    draw            = draw,
                    data            = mapper.MapTo <List <TResult> >(resultFilter),
                    recordsFiltered = count,
                    recordsTotal    = count
                };

                return(Task.FromResult(result));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #15
0
        public async Task <JsonResult> Login([FromForm] AuthenticationModel login)
        {
            _logger.LogInformation("test");
            var user = await _userManager.GetAsync(x => x.Username == login.UserName.ToLower());

            if (user == null)
            {
                return(new JsonResult(new ResponseModel(errors: new List <string> {
                    $"There is no registered user with username {login.UserName}"
                },
                                                        success: false,
                                                        code: HttpStatusCode.BadRequest,
                                                        message: "Authentication failed!"
                                                        )));
            }

            if (!Password.Verify(string.IsNullOrEmpty(login.Password) ? "" : login.Password, user.Password))
            {
                return(new JsonResult(new ResponseModel(
                                          errors: new List <string> {
                    "Wrong username or password"
                },
                                          success: false,
                                          code: HttpStatusCode.BadRequest,
                                          message: "Authentication failed!"
                                          )));
            }

            user.LastLoginTime = DateTime.Now;
            await _userManager.UpdateAsync(user);

            var tokenString = GenerateJSONWebToken(user.Id);
            var userDetails = CustomMapper <UserEntity, UserDto> .Map(user);

            return(new JsonResult(new ResponseModel(
                                      code: HttpStatusCode.OK,
                                      message: "Success",
                                      data: new
            {
                user = userDetails,
                expires = (DateTime.Now.AddDays(1) - DateTime.Now).TotalSeconds,
                accessToken = tokenString,
            })));
        }
        public void TestGetSummary()
        {
            User user1 = new User()
            {
                UserSummary = new Summary()
                {
                    Name = "summary1"
                }
            };
            User user2 = new User()
            {
                UserSummary = new Summary()
                {
                    Name = "summary2"
                }
            };
            User user3 = new User()
            {
                UserSummary = new Summary()
                {
                    Name = "summary3"
                }
            };
            List <User> users = new List <User>()
            {
                user1, user2, user3
            };

            mockUnitOfWork     = kernel.Get <IUnitOfWork>();
            mockUserRepository = kernel.Get <IGenericRepository <User> >();
            mockUserRepository.Get().Returns(users);
            mockUnitOfWork.UsersRepository.Returns(mockUserRepository);

            presentSubSys = new PresentSubSystem(mockUnitOfWork);

            List <SummaryBLL> expected = new List <SummaryBLL>()
            {
                CustomMapper.getSummaryBLL(user1.UserSummary), CustomMapper.getSummaryBLL(user2.UserSummary), CustomMapper.getSummaryBLL(user3.UserSummary)
            };
            List <SummaryBLL> real = (List <SummaryBLL>)presentSubSys.GetSummary();

            Assert.AreEqual(expected, real);
        }
예제 #17
0
        public ConsumerEmployeeViewModel(ConsumerEmployee model)
        {
            CustomMapper.MapEntity(model, this);
            var employeeFiles = ConsumerEmployeeManagement.GetFilesByConsumerEmployeeId(model.ConsumerEmployeeId).FirstOrDefault();

            FileId   = employeeFiles?.Id;
            FileName = employeeFiles?.FileDisplayName;

            this.ContactName = model.Contact.FirstName + " " + model.Contact.LastName;
            if (this.ServiceId.HasValue)
            {
                this.ServiceName = model.ServicesList.ServiceDescription;
            }

            if (model.Contact.AgencyNameId.HasValue)
            {
                this.CompanyName = model.Contact.Agency.NameCompany;
            }
        }
        public void TestGetFilteredSummaries()
        {
            User user1 = new User()
            {
                UserSummary = new Summary()
                {
                    Name = "summary1", Position = "worker", Salary = 1000
                }
            };
            User user2 = new User()
            {
                UserSummary = new Summary()
                {
                    Name = "summary2", Position = "teacher", Salary = 4000
                }
            };
            User user3 = new User()
            {
                UserSummary = new Summary()
                {
                    Name = "summary3", Position = "worker", Salary = 8000
                }
            };
            List <User> users = new List <User>()
            {
                user1, user2, user3
            };

            mockUnitOfWork     = kernel.Get <IUnitOfWork>();
            mockUserRepository = kernel.Get <IGenericRepository <User> >();
            mockUserRepository.Get().Returns(users);
            mockUnitOfWork.UsersRepository.Returns(mockUserRepository);

            presentSubSys = new PresentSubSystem(mockUnitOfWork);

            List <SummaryBLL> expected = new List <SummaryBLL>()
            {
                CustomMapper.getSummaryBLL(user1.UserSummary)
            };
            List <SummaryBLL> real = (List <SummaryBLL>)presentSubSys.GetFilteredSummaries("worker", 6000, "Name");

            Assert.AreEqual(expected, real);
        }
예제 #19
0
        private async Task DistributeCards(List <GamePlayer> players, int cardAmountPerPlayer, bool doesDealerNeedCards = true)
        {
            var         createdPlayerCards = new List <PlayerCard>();
            int         cardAmount         = players.Count() * cardAmountPerPlayer;
            List <Card> deck = await _cardRepository.GetSpecifiedAmount(cardAmount);

            foreach (GamePlayer player in players)
            {
                if (doesDealerNeedCards || player.Player.Type != PlayerType.Dealer)
                {
                    List <Card>       cards = PopCardsFromDeck(deck, cardAmountPerPlayer);
                    List <PlayerCard> createdPlayerCardsForPlayer = CustomMapper.MapPlayerCards(player, cards);
                    player.PlayerCards.AddRange(createdPlayerCardsForPlayer);
                    createdPlayerCards.AddRange(createdPlayerCardsForPlayer);
                }
            }

            await _playerCardRepository.CreateMany(createdPlayerCards);
        }
예제 #20
0
        public async Task <EndRoundView> End(long gameId)
        {
            List <GamePlayer> players = await _gamePlayerRepository.GetAllByGameId(gameId);

            GamePlayer human  = players.Where(m => m.Player.Type == PlayerType.Human).First();
            GamePlayer dealer = players.Where(m => m.Player.Type == PlayerType.Dealer).First();

            await DistributeEndCardsForDealer(dealer);

            string roundResult = GetRoundResult(human, dealer);
            Game   game        = CustomMapper.MapGame(gameId, roundResult);
            await _gameRepository.Update(game);

            await _historyMessageManager.AddMessagesForRound(players, roundResult, gameId);

            EndRoundView view = CustomMapper.MapEndRoundView(dealer, roundResult);

            return(view);
        }
예제 #21
0
        static Repository()
        {
            var mapper = new CustomMapper();

            mapper.Entity <DefaultFoodUnit>().DbRef(x => x.FoodUnit).Ignore(x => x.NutrientsPer1G).Ignore(x => x.NutrientsPer100G);
            mapper.Entity <Food>().DbRef(x => x.Units);
            mapper.Entity <MealFood>().DbRef(x => x.Food).DbRef(x => x.FoodUnit).Ignore(x => x.Nutrients);
            mapper.Entity <MealTemplate>().Ignore(x => x.Nutrients);
            mapper.Entity <EatingDay>().Ignore(x => x.Nutrients);

            mapper.Entity <Macros>()
            .Ignore(x => x.Calories)
            .Ignore(x => x.CarbsPercentage)
            .Ignore(x => x.ProteinPercentage)
            .Ignore(x => x.FatsPercentage)
            .Ignore(x => x.AlcoholPercentage);

            BsonMapper.Global = mapper;
        }
예제 #22
0
        private async Task <List <Player> > CreatePlayerList(long playerId, int amountOfBots)
        {
            var    players = new List <Player>();
            var    random  = new Random();
            Player dealer  = CustomMapper.GetPlayer(((BotName)random.Next(GameValueHelper.BotNameAmount)).ToString(), PlayerType.Dealer);

            players.Add(dealer);

            for (int i = 0; i < amountOfBots; i++)
            {
                Player bot = CustomMapper.GetPlayer(((BotName)random.Next(GameValueHelper.BotNameAmount)).ToString(), PlayerType.Bot);
                players.Add(bot);
            }

            players = await _playerRepository.CreateMany(players);

            players.Add(await _playerRepository.Get(playerId));
            return(players);
        }
        public void Get_WhenCalled_ReturnsOkResult()
        {
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper _customMapper = new CustomMapper(context);
                // Arrange
                IDataRepository <Recipe> mockRepository = Substitute.For <IDataRepository <Recipe> >();
                RecipeController         recipeCont     = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                FilterModel fm = new FilterModel();
                // Act

                var okResult = recipeCont.Get(fm);

                // Assert
                Assert.IsType <ActionResult <PagedCollectionResponse <RecipeViewModel> > >(okResult);
            }
        }
예제 #24
0
        public async Task <JsonResult> CreateDirectory([FromForm] CreateDirectoryDto input)
        {
            var fileEntity = CustomMapper <CreateDirectoryDto, FileEntity> .Map(input);

            long userId = long.Parse(User.Identity.Name);

            fileEntity.OwnerId = userId;
            bool exists = await _fileManager.IsExist(fileEntity.ParentId, fileEntity.OwnerId, fileEntity.Name);

            if (exists)
            {
                return(new JsonResult(new ResponseModel(message: "Error while creating directory", code: HttpStatusCode.BadRequest, success: false, errors: new List <string> {
                    $"Folder with name {input.Name} already exists"
                })));
            }
            var created = await _fileManager.CreateAsync(fileEntity);


            string DbPath        = "";
            string directoryPath = "";
            string folderName    = created.Id.ToString();

            if (input.ParentId == 0)
            {
                var user = await _userManager.GetAsync(u => u.Id == userId);

                directoryPath = Path.Combine(StorageDirectory, user.Username, folderName);
                DbPath        = Path.Combine(AppConsts.StorageDirectory, user.Username, folderName);
            }
            else
            {
                var parent = await _fileManager.GetAsync(input.ParentId);

                directoryPath = Path.Combine(_env.WebRootPath, parent.Path, folderName);
                DbPath        = Path.Combine(parent.Path, folderName);
            }

            Directory.CreateDirectory(directoryPath);
            fileEntity.Path = DbPath;
            await _fileManager.UpdateAsync(fileEntity);

            return(new JsonResult(new ResponseModel(message: "Succesfully created")));
        }
예제 #25
0
        public async Task <JsonResult> Create([FromForm] CreateUserDto input)
        {
            if (ModelState.IsValid)
            {
                var user = CustomMapper <CreateUserDto, UserEntity> .Map(input);

                try
                {
                    user.Password       = Password.Hash(user.Password);
                    user.Username       = user.Username.ToLower();
                    user.Email          = user.Email.ToLower();
                    user.FilesDirectory = Path.Combine(AppConsts.StorageDirectory, user.Username);
                    Directory.CreateDirectory(Path.Combine(_env.WebRootPath, user.FilesDirectory));
                    await _userManager.CreateAsync(user);

                    return(new JsonResult(new ResponseModel("Success")));
                }
                catch (Exception ex)
                {
                    SqlException  exp    = ex.InnerException as SqlException;
                    List <string> errmsg = new List <string>();
                    if (exp.Number == 2601 || exp.Number == 2627)
                    {
                        string constraint = exp.Message.Substring(exp.Message.LastIndexOf('_') + 1);
                        errmsg.Add($"{constraint.Split('\'').First()} already exists");
                    }
                    return(new JsonResult(new ResponseModel(code: HttpStatusCode.BadRequest, errors: errmsg, success: false)));
                }
            }
            else
            {
                List <string> errorMsg = new List <string>();
                foreach (var key in ModelState.Values)
                {
                    foreach (var err in key.Errors)
                    {
                        errorMsg.Add(err.ErrorMessage);
                    }
                }
                return(new JsonResult(new ResponseModel(code: HttpStatusCode.PartialContent, success: false, errors: errorMsg)));
            }
        }
예제 #26
0
        public async Task <ActionResult> SendEmail(int noteId, String email, string emailBody, String contactName)
        {
            if (User == null)
            {
                return(null);
            }
            ConsumerNotesManagement manage = new ConsumerNotesManagement(_context);
            var note = await manage.GetNote(noteId);

            var mappedData = CustomMapper.MapEntity <ConsumerNote, CustomerNotesBoundModel>(note);

            mappedData.InnerEmailBody = emailBody;
            List <Object> emailInputData = new List <object>()
            {
                mappedData
            };
            await EmailService.SendBoundEmail(email, contactName, "Notes Email", "note-email", emailInputData, User?.Identity?.Name);

            return(Json(new { status = "ok" }));
        }
        public ActionResult Save(ConsumerServiceCoordinatorViewModel viewModel)
        {
            if (User == null)
            {
                return(null);
            }
            object result     = null;
            var    inputModel = CustomMapper.MapEntity <BaseConsumerServiceCoordinatorModel>(viewModel);

            if (ConsumerServiceCoordinatorManagement.Validate(_context, inputModel))
            {
                var entity = ConsumerServiceCoordinatorManagement.CreateOrUpdate(_context, inputModel);
                result = new { status = "ok", model = CustomMapper.MapEntity <ConsumerServiceCoordinatorViewModel>(entity), New = viewModel.Id == 0 };
            }
            else
            {
                result = new { status = "error", errorMessage = "not valid date range for MSC" };
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public void Put_Null_Should_ReturnsBadRequest()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper            _customMapper  = new CustomMapper(context);
                IDataRepository <Recipe> mockRepository = new RecipeManager(context);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                //Act


                var badRequest = recipecontroller.Put(1, null);

                // Assert
                Assert.IsType <Microsoft.AspNetCore.Mvc.BadRequestObjectResult>(badRequest);
            }
        }
예제 #29
0
 public object CheckUser(string login, string password)
 {
     password = DecryptPassword(password);
     if (uow.UsersRepository.Get().FirstOrDefault(c => c.Login == login && c.Password == password) != null)
     {
         return(CustomMapper.getUserBLL(uow.UsersRepository.Get().FirstOrDefault(c => c.Login == login && c.Password == password)));
     }
     if (uow.RecruitersRepository.Get().FirstOrDefault(c => c.Login == login && c.Password == password) != null)
     {
         return(CustomMapper.getRecruiterBLL(uow.RecruitersRepository.Get().FirstOrDefault(c => c.Login == login && c.Password == password)));
     }
     if (uow.AdminsRepository.Get().FirstOrDefault(c => c.Login == login && c.Password == password) != null)
     {
         return(CustomMapper.getAdminBLL(uow.AdminsRepository.Get().FirstOrDefault(c => c.Login == login && c.Password == password)));
     }
     else
     {
         return(null);
     }
 }
예제 #30
0
        private async Task <List <Player> > CreatePlayerList(string humanName, int amountOfBots)
        {
            var    players = new List <Player>();
            Player human   = CustomMapper.MapPlayer(humanName, PlayerType.Human);

            players.Add(human);

            Player dealer = CustomMapper.MapPlayer(PlayerName.DealerName, PlayerType.Dealer);

            players.Add(dealer);

            for (int i = 0; i < amountOfBots; i++)
            {
                Player bot = CustomMapper.MapPlayer(PlayerName.BotName + i, PlayerType.Bot);
                players.Add(bot);
            }

            players = await _playerRepository.CreateMany(players);

            return(players);
        }
        public void Put_Invalid_ID_Should_ReturnsNotFoundResult()
        {
            // Arrange
            DbContextOptions <RepositoryContext> options = new MockDBHandler().CategoryWithThreeMember().CountryWithThreeMember().UnitWithThreeMember().IngredientWithThreeMember().ReciptWithThreeMember().build();

            using (var context = new RepositoryContext(options))
            {
                ICustomMapper            _customMapper  = new CustomMapper(context);
                IDataRepository <Recipe> mockRepository = new RecipeManager(context);

                RecipeController recipecontroller = new RecipeController(mockRepository, _mapper, _customMapper, _usermanager);
                //Act
                var forEdit = new MockDBHandler().buildMockRecipeView();
                forEdit.ID = 1; // Because In mock it is something else and in equalation assert result to false

                var notFoundResult = recipecontroller.Put(68, forEdit);

                // Assert
                Assert.IsType <Microsoft.AspNetCore.Mvc.NotFoundObjectResult>(notFoundResult);
            }
        }
예제 #32
0
        public AccountService(IRepository repository, CustomMapper mapper, IBonus bonus)
        {
            if (repository is null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (bonus is null)
            {
                throw new ArgumentNullException(nameof(bonus));
            }

            if (mapper is null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            this.bonus      = bonus;
            this.repository = repository;
            this.mapper     = mapper;
        }
        public async Task <ActionResult> SendEmail(int serviceId, String email, string emailBody, String contactName)
        {
            if (User == null)
            {
                return(null);
            }
            ConsumerServicesManagement manage = new ConsumerServicesManagement(_context);
            var service = await manage.GetService(serviceId, true);

            var mappedData = CustomMapper.MapEntity <ConsumerServiceModel, ApprovedServiceBoundModel>(service);

            mappedData.ConsumerEmployeeList = CustomMapper.MapList <ConsumerEmployeeModel, ConsumerEmployeeModel>(service.ConsumerEmployeeList);
            mappedData.InnerEmailBody       = emailBody;
            List <Object> emailInputData = new List <object>()
            {
                mappedData
            };
            await EmailService.SendBoundEmail(email, contactName, "Approver Service Email", "apporved-service-email", emailInputData, User?.Identity?.Name);

            return(Json(new { status = "ok" }));
        }