Exemplo n.º 1
0
        public Request ToModel(RequestViewModel requestViewModel, IMediator mediator)
        {
            var request = new Request
            {
                ProviderId = requestViewModel.ProviderId,
                ProviderData = requestViewModel.ProviderData,
                Address = requestViewModel.Address,
                City = requestViewModel.City,
                DateAdded = DateTime.UtcNow,
                Email = requestViewModel.Email,
                Name = requestViewModel.Name,
                Phone = requestViewModel.Phone,
                State = requestViewModel.State,
                Zip = requestViewModel.Zip,
                Status = RequestStatus.Unassigned,
                Latitude = requestViewModel.Latitude,
                Longitude = requestViewModel.Longitude
            };

            RequestStatus status;
            if (Enum.TryParse(requestViewModel.Status, out status))
            {
                request.Status = status;
            }

            return request;
        }
        public async Task PostSendsAddRequestCommandAsyncWithCorrectData()
        {
            var mediator = new Mock<IMediator>();
            var sut = new RequestApiController(mediator.Object);
            var ourViewModel = new RequestViewModel
            {
                ProviderId = "Crazy-Eights",
                ProviderData = "Go-Fish",
                Address = "Address",
                City = "Citty",
                State = "Sttate",
                Zip = "ZZiipp",
                Phone = "Fone",
                Name = "ONAMEO",
                Email = "ANEMAILADDRESS",
                Status = RequestStatus.Assigned.ToString()
            };

            await sut.Post(ourViewModel);

            mediator.Verify(x => x.SendAsync(It.Is<AddRequestCommandAsync>(y => y.Request.ProviderId == ourViewModel.ProviderId
            && y.Request.Status == RequestStatus.Assigned
            && y.Request.ProviderData == ourViewModel.ProviderData
            && y.Request.State == ourViewModel.State
            && y.Request.Address == ourViewModel.Address
            && y.Request.City == ourViewModel.City
            && y.Request.Phone == ourViewModel.Phone
            && y.Request.Zip == ourViewModel.Zip
            && y.Request.Name == ourViewModel.Name
            && y.Request.Email == ourViewModel.Email)), Times.Once);
        }
        public async Task PostReturnsCreatedResult()
        {
            var mediator = new Mock<IMediator>();
            var viewModel = new RequestViewModel {ProviderId = "ProviderId", RequestId = Guid.NewGuid().ToString()};

            var sut = new RequestApiController(mediator.Object);
            var result = await sut.Post(viewModel);

            Assert.IsType<CreatedResult>(result);
        }
        public async Task PostSendsAddRequestCommandWithTheCorrectParameters()
        {
            var mediator = new Mock<IMediator>();
            var viewModel = new RequestViewModel {ProviderId = "ProviderId", RequestId = Guid.NewGuid().ToString()};

            var sut = new RequestApiController(mediator.Object);
            await sut.Post(viewModel);

            mediator.Verify(x => x.SendAsync(It.Is<AddApiRequestCommand>((y => y.RequestViewModel == viewModel))));
        }