示例#1
0
        public Guid AddAlarmsRecord(AddAlarmsRecordDto record)
        {
            var toStore = _mapper.Map <AlarmsRecord>(record);

            _repo.Add(toStore);
            _repo.SaveChanges();

            return(toStore.Id);
        }
        public IActionResult Create([FromBody] AddAlarmsRecordDto record)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var id = _alarmsService.AddAlarmsRecord(record);

            return(Created("api/v1/alarms/" + id, id));
        }
        public void Given_Create_When_ValidModelState_Then_ShouldRespondWithCreated()
        {
            //Arrange
            var addRecord = new AddAlarmsRecordDto();
            var id        = new Guid();

            Service.Setup(serv => serv.AddAlarmsRecord(addRecord))
            .Returns(id);

            var controller = CreateSut();

            //Act
            var response = controller.Create(addRecord);

            //Assert
            response.Should().BeOfType <CreatedResult>();
        }
        public void Given_Create_When_InvalidModelState_Then_ShouldRespondWithBadRequest()
        {
            //Arrange
            var addRecord = new AddAlarmsRecordDto();
            var id        = new Guid();

            Service.Setup(serv => serv.AddAlarmsRecord(addRecord))
            .Returns(id);

            var controller = CreateSut();

            controller.ModelState.SetModelValue("", ValueProviderResult.None);

            //Act
            var response = controller.Create(addRecord);

            //Assert
            response.Should().BeOfType <BadRequestResult>();
        }