示例#1
0
        public void Map_MapFromBarRepDtoToBarRep_CorrectType()
        {
            var barRepDto = new BarRepresentativeDto();
            var barRep    = uut.Map <BarRepresentative>(barRepDto);

            Assert.That(barRep, Is.TypeOf <BarRepresentative>());
        }
示例#2
0
 public IActionResult EditBarRepresentative([FromBody] BarRepresentativeDto barRepDto)
 {
     try
     {
         var barRep = _mapper.Map <BarRepresentative>(barRepDto);
         _unitOfWork.BarRepRepository.Edit(barRep);
         _unitOfWork.Complete();
         return(Created(string.Format($"api/BarRepresentative/{barRep.Username}"), barRepDto));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
示例#3
0
        public void Setup()
        {
            mockUnitOfWork = Substitute.For <IUnitOfWork>();

            var profile       = new MappingProfile();
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(profile));

            mapper = new Mapper(configuration);

            uut = new BarRepresentativeController(mockUnitOfWork, mapper);

            defaultList = new List <BarRepresentative>()
            {
                new BarRepresentative()
                {
                    BarName  = "TestBar",
                    Name     = "Navn1",
                    Username = "******",
                    Bar      = null,
                },
                new BarRepresentative()
                {
                    BarName  = "TestBar2",
                    Name     = "Navn2",
                    Username = "******",
                    Bar      = null,
                }
            };
            defaultBarRep = defaultList[0];

            // Direct conversion without navigational property
            correctResultList = new List <BarRepresentativeDto>()
            {
                new BarRepresentativeDto()
                {
                    BarName  = "TestBar",
                    Name     = "Navn1",
                    Username = "******",
                },
                new BarRepresentativeDto()
                {
                    BarName  = "TestBar2",
                    Name     = "Navn2",
                    Username = "******",
                }
            };
            defaultBarRepDto = correctResultList[0];
        }
示例#4
0
 public IActionResult AddBarRepresentative([FromBody] BarRepresentativeDto barRepDto)
 {
     try
     {
         var barRep = _mapper.Map <BarRepresentative>(barRepDto);
         _unitOfWork.BarRepRepository.Add(barRep);
         _unitOfWork.Complete();
         return(Created(string.Format($"api/BarRepresentative/{barRep.Username}"), barRepDto));
     }
     catch (Exception e)
     {
         if (e.InnerException is SqlException exception && exception.Number == 2627)
         {
             return(BadRequest("Duplicate Key"));
         }
         return(BadRequest());
     }
 }