public void Handle(CreateParkingCommand command) { var places = Enumerable.Range(1, command.Capacity) .Select(n => { return(new ParkingPlace { ParkingName = command.ParkingName, Number = n, IsFree = true }); }) .ToList(); var parking = new Models.Parking { Name = command.ParkingName, IsOpened = true, Places = places }; _dbContext.Add(parking); _dbContext.SaveChanges(); _commandStoreService.Push(command); }
public async Task Should_CreateParking() { // Arrange var LHandleCreateParking = new CreateParkingCommandHandler(FMockDbContext.Object, FCommands); var LCommand = new CreateParkingCommand { ParkingName = "Best Parking", Capacity = 1000 }; // Act var LResult = await LHandleCreateParking.Handle(LCommand, CancellationToken.None); // Assert FMockDbContext .Verify(AMockDbContext => AMockDbContext.SaveChangesAsync(CancellationToken.None), Times.Once); LResult.ToString().Should().Be("()"); }
public void CreateParking([FromBody] CreateParkingRequest request) { var command = new CreateParkingCommand(request.ParkingName, request.Capacity); _commandRouter.Handle(command); }