public async Task <ResponseDTO> Register(RegisterLocationRequest location) { if (ModelState.IsValid) { return(await _locationApplicationService.RegisterLocationAsync(location)); } return(ModelState.ToResponse()); }
public async Task <ResponseDTO> RegisterLocationAsync(RegisterLocationRequest newLocation) { //Map to Command var command = _mapper.Map <RegisterLocationRequest, RegisterLocationCommand>(newLocation); //Execute Command var resp = await _bus.SendAsync(command); return(resp.ToResponse()); }
private async Task LocationRegistration() { // all portable cash registers are required to register their location, after their location change. // location can be specified in three forms: // 1, GPS coordinates GeoCoordinates locationGps = new GeoCoordinates( longitude: 17.165377m, latitude: 48.148962m); // 2, Address PhysicalAddress addressLocation = new PhysicalAddress( streetName: "Kresánkova", municipality: "Bratislava", buildingNumber: "12", postalCode: "84105", propertyRegistrationNumber: 3597); // 3, Free form, such as car licence plate. CashRegisterOtherLocation locationOther = new CashRegisterOtherLocation( "Taxi, ŠPZ: BL-123AA"); // wrap location to cash register location object, to pair this location with cash register code. CashRegisterLocation cashRegisterLocation = new CashRegisterLocation(cashRegisterCode, addressLocation); // wrap cashRegisterLocation to request object. RegisterLocationRequest request = new RegisterLocationRequest(cashRegisterLocation); // finally, send location registration to eKasa server. RegisterLocationResult registrationResult = await client .RegisterLocationAsync(request, CancellationToken.None) .ConfigureAwait(false); // registration result analysis is similiar to receipt. There are three scenarios: if (registrationResult.IsSuccessful == true) { // 1, location has been registered in ONLINE mode and has been successful. } else if (registrationResult.IsSuccessful == null) { // 2, location has been registered in OFFLINE mode. // the library will try to send this offline message later, when connection with ekasa server will be established. } else if (registrationResult.IsSuccessful == false) { // 3, location registration has failed. Please see error for more details. EKasaError error = registrationResult.Error; } }
public async Task RegisterLocation_Call() { //-------------- Arrange ------------- CommonArrangements(); var request = new RegisterLocationRequest(); var command = new RegisterLocationCommand(); A.CallTo(() => mapper.Map <RegisterLocationRequest, RegisterLocationCommand>(request)).Returns(command); //-------------- Act ------------- var resp = locationService.RegisterLocationAsync(request); //-------------- Assert ------------- A.CallTo(() => bus.SendAsync(command)).MustHaveHappened(Repeated.Exactly.Once); }