示例#1
0
        public void Map_MapFromBarEventDtoToBarEvent_CorrectType()
        {
            var barEventDto = new BarEventDto();
            var barEvent    = uut.Map <BarEvent>(barEventDto);

            Assert.That(barEvent, Is.TypeOf <BarEvent>());
        }
示例#2
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 EventController(mockUnitOfWork, mapper);

            defaultList = new List <BarEvent>()
            {
                new BarEvent()
                {
                    BarName   = "TestBar",
                    EventName = "Høst Fest",
                    Image     = "fest.jpg",
                    Date      = DateTime.Now,
                    Bar       = null,
                },
                new BarEvent()
                {
                    BarName   = "TestBar",
                    EventName = "Fadøl til en 10'er",
                    Image     = "fadøl.jpg",
                    Date      = DateTime.Now,
                    Bar       = null,
                }
            };
            defaultEvent = defaultList[0];

            // Direct conversion without navigational property
            correctResultList = new List <BarEventDto>()
            {
                new BarEventDto()
                {
                    BarName   = "TestBar",
                    EventName = "Høst Fest",
                    Image     = "fest.jpg",
                    Date      = DateTime.Now,
                },
                new BarEventDto()
                {
                    BarName   = "TestBar",
                    EventName = "Fadøl til en 10'er",
                    Image     = "fadøl.jpg",
                    Date      = DateTime.Now,
                }
            };
            defaultEventDto = correctResultList[0];
        }
示例#3
0
 public IActionResult EditEvent([FromBody] BarEventDto eventDto)
 {
     try
     {
         var barEvent = _mapper.Map <BarEvent>(eventDto);
         _unitOfWork.BarEventRepository.Edit(barEvent);
         _unitOfWork.Complete();
         return(Created(string.Format($"api/bars/{barEvent.BarName}/events"), eventDto));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
示例#4
0
 public IActionResult AddEvent([FromBody] BarEventDto eventDto)
 {
     try
     {
         var barEvent = _mapper.Map <BarEvent>(eventDto);
         _unitOfWork.BarEventRepository.Add(barEvent);
         _unitOfWork.Complete();
         return(Created(string.Format($"api/bars/{barEvent.BarName}/events"), eventDto));
     }
     catch (Exception e)
     {
         if (e.InnerException is SqlException exception && exception.Number == 2627)
         {
             return(BadRequest("Duplicate Key"));
         }
         return(BadRequest());
     }
 }