Exemplo n.º 1
0
        public IActionResult Edit(BeaconViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var beaconToUpdate = Mapper.Map <Beacon>(vm);

                // save to database
                _repository.Edit(beaconToUpdate);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public IActionResult Create(BeaconViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newBeacon = Mapper.Map <Beacon>(vm);

                // save to database
                _repository.AddBeacon(newBeacon);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public async Task HandlerReturnsCorrectUserViewModel()
        {
            // Arrange
            var beaconQueryHandlerAsync = new BeaconQueryHandlerAsync();

            var beaconQuery = new BeaconQuery {
                Id = 1
            };

            // Act
            BeaconViewModel beaconViewModel = await beaconQueryHandlerAsync.Handle(beaconQuery);

            // Assert
            beaconViewModel.Should().NotBeNull();
        }
Exemplo n.º 4
0
        public async void GetById_WithProperUserId_ReturnsBeaconViewModel()
        {
            // Arrange
            const int userId = 1;

            var beaconViewModel = new BeaconViewModel
            {
                Id = 2123
            };

            BeaconService beaconService = beaconServiceBuilder
                                          .WithBeaconViewModel(beaconViewModel)
                                          .Build();

            // Act
            BeaconViewModel beaconViewModelResult = await beaconService.GetById(userId);

            // Assert
            beaconViewModelResult.Should().NotBeNull();
            beaconViewModelResult.Id.Should().Be(beaconViewModel.Id);
        }
        public SubmissionStatus Put([FromBody] BeaconViewModel beacon)
        {
            SubmissionStatus status = new SubmissionStatus();

            status.StatusCode = SubmissionStatusCode.Success;

            try
            {
                // Add the beacon
                IList <string> errors = this.dataLogic.UpdateBeacon(beacon.Id, beacon.UUID, beacon.BeaconId, beacon.MinorVersion, beacon.MajorVersion, beacon.FriendlyName, beacon.Location);
                if (errors.Count > 0)
                {
                    status.Messages   = errors.ToList();
                    status.StatusCode = SubmissionStatusCode.Failure;
                }
            }
            catch (Exception ex)
            {
                status.Messages.Add(ex.Message);
                status.StatusCode = SubmissionStatusCode.Failure;
            }

            return(status);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Get(Guid id)
        {
            BeaconViewModel beaconViewModel = await beaconService.GetById(id);

            return(new ObjectResult(beaconViewModel));
        }
Exemplo n.º 7
0
        public BeaconServiceBuilder WithBeaconViewModel(BeaconViewModel beaconViewModel)
        {
            this.mockMediator.Setup(x => x.SendAsync(It.IsAny <BeaconQuery>())).Returns(Task.FromResult(beaconViewModel));

            return(this);
        }