public async Task GetAsync() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; IOptions <OperationalStoreOptions> someOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(options, someOptions)) { var orders = new[] { new Order { Id = 1, FullPrice = 1 }, }; context.Orders.AddRange(orders); context.SaveChanges(); var orderService = new OrderService(context); await orderService.AddAsync(new Order { Id = 2, FullPrice = 2 }); Assert.AreEqual( 2, (await orderService.GetAsync()).Count ); } }
public async Task TestAddOrder() { var id = Guid.NewGuid(); var service = new OrderService(_repositoryMock.Object, _serverClientMock.Object, _batchClientMock.Object, _configMock.Object, _cancellationServiceMock.Object, _loggerMock.Object); await service.AddAsync(_cancellationServiceMock.Object.GetToken(), id, 5, 5); _repositoryMock.Verify(x => x.AddAsync(_cancellationServiceMock.Object.GetToken(), It.IsAny <Order>()), Times.Once); }
public async Task AddOrderAsyncValidDataTest() { AddOrderModel addOrderModel = CreateAddOrderModel(Token); SessionData sessionData = CreateSessionData(); UserData userData = CreateUserData(); ClientData clientData = CreateClientData(); SetupSessionRepositoryMock(addOrderModel.Token, sessionData); SetupApplicationUserRepositoryMock(sessionData.UserId, userData); SetupClientRepositoryMock(clientData, userData.Id); SetupOrderRepositoryAddAsyncMock(addOrderModel, clientData.Id); SetupRoomAvailabilityHandlerMock(addOrderModel, DatesAreValid, RoomIsAvailable); DefaultResponseModel expected = CreateSuccessfulDefaultResponseModel(); var actual = await orderService.AddAsync(addOrderModel); Assert.AreEqual(expected.IsSuccessful, actual.IsSuccessful); }
public async Task <ActionResult> CreatePostAsync([FromBody] Order value) { _logger.LogDebug("Inserting Order"); if (await _orderService.AddAsync(value)) { _logger.LogDebug("Insert operation Success."); return(Ok()); } _logger.LogDebug("Insert operation failed"); return(BadRequest()); }
public async Task <IActionResult> Create([Bind("Id,FullPrice,IsPaid,IsDelivered")] Order order) { if (ModelState.IsValid) { await _orderService.AddAsync(order); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public async Task AddOrderSuccessfullyAsyncTest() { var orderInput = new Order { CustomerId = 1, Address = "Albatrosvagern", CreatedAt = DateTime.Now, Status = OrderStatus.Pending, OrderItems = new List <OrderItem> { new OrderItem { NoOfItem = 10, PorductId = 1, } } }; var returnOrder = new Order { CustomerId = 1, Address = "Albatrosvagern", CreatedAt = DateTime.Now, Status = OrderStatus.Pending, OrderItems = new List <OrderItem> { new OrderItem { NoOfItem = 10, PorductId = 1, } } }; _mockorderRepository.Setup(repo => repo.GetLastOrderId()).Returns(2); _mockbaserepository.Setup(repo => repo.AddAsync(orderInput)).Returns(Task.Run(() => returnOrder)); var service = new OrderService(_mockbaserepository.Object, _mockorderRepository.Object); var order = await service.AddAsync(orderInput); _mockbaserepository.Verify(x => x.AddAsync(It.Is <Order>(actualOrder => actualOrder.OrderNumber == "SO1002")), Times.Once); Assert.Equal(returnOrder, order); }
public async Task TestPostingABackGeneratorToExternalServices() { //setup valid order with valid batch var id = Guid.NewGuid(); var batchCount = 4; var numberPerBatch = 5; var updatedCount = 5; var order = new Order(id, batchCount, numberPerBatch); var completedPerBatch = new List <Batch> { new Batch("1", updatedCount), new Batch("2", updatedCount) }; order.TotalOrdersCount = batchCount * numberPerBatch; order.CompletedPerBatch = completedPerBatch; //mock the configuration and client services var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); _configMock.Setup(x => x.GetSection("ExternalService")).Returns(config.GetSection("ExternalService")); _repositoryMock.Setup(x => x.GetAsync(_cancellationServiceMock.Object.GetToken(), id)).ReturnsAsync(order); _repositoryMock.Setup(x => x.AddAsync(_cancellationServiceMock.Object.GetToken(), order)).Returns(Task.FromResult(order)); _serverClientMock.Setup(x => x.PostAsync(_cancellationServiceMock.Object.GetToken(), order, "Generator")).ReturnsAsync(true); var service = new OrderService(_repositoryMock.Object, _serverClientMock.Object, _batchClientMock.Object, _configMock.Object, _cancellationServiceMock.Object, _loggerMock.Object); await service.UpdateBatch(_cancellationServiceMock.Object.GetToken(), id, "1", 5); //If will call Multiplier service if batch not complete and will not call if it is complete await service.AddAsync(_cancellationServiceMock.Object.GetToken(), order.OrderId, batchCount, numberPerBatch); _serverClientMock.Verify(x => x.PostAsync(_cancellationServiceMock.Object.GetToken(), It.IsAny <Order>(), "Generator"), Times.Once); }
public async Task <IActionResult> Post([FromBody] OrderAddCommand command) { try { return(Ok ( await service.AddAsync(command, ArticleController.GetPathTemplate(Request)) )); } catch (DuplicateWaitObjectException ex) { return(Conflict(ex.Message)); } catch (HttpRequestException ex) { return(StatusCode(StatusCodes.Status503ServiceUnavailable, ex.Message)); //return BadRequest(ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.ToString()); return(BadRequest(Error)); } }
public async Task <IActionResult> Add([FromQuery] OrderModel orderModel) => Json(await _orderService.AddAsync(orderModel));