public async Task GetLicenseRequest_WhenDataExists_ShouldReturnCorrectObject(string url)
        {
            // Arrange
            var client         = _factory.CreateClient();
            var licenseRequest = new LicenseRequestModel
            {
                CompanyName   = "",
                ContactPerson = "George",
                Address       = "Giesing",
                Email         = "*****@*****.**",
                LicenseKey    = "empty"
            };
            var content = new StringContent(JsonConvert.SerializeObject(licenseRequest), Encoding.UTF8, "application/json");

            // Act
            var response = await client.PostAsync(url, content);

            var resourse = response.Headers.Location;

            response = await client.GetAsync(resourse);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.Equal("application/json; charset=utf-8",
                         response.Content.Headers.ContentType.ToString());

            var body = await response.Content.ReadAsStringAsync();

            var licenseResponse = JsonConvert.DeserializeObject <LicenseResponseModel>(body);

            Assert.NotEqual(Guid.Empty, licenseResponse.Id);
            Assert.Equal(licenseRequest.ContactPerson, licenseResponse.ContactPerson);
        }
Beispiel #2
0
        public IActionResult SendLicenseRequest([FromBody] LicenseRequestModel licenseRequestModel)
        {
            var licenseDataModel = _mapper.Map <LicenseDataModel>(licenseRequestModel);

            //queque for the websocket to pickup
            _queueService.Enqueue(
                _mapper.Map <LicenseMessage>(licenseDataModel)
                );

            //store for the consumer to get updates
            _storageService.AddOrUpdate(licenseDataModel);

            //201 response (REST)
            var licenseResponse = _mapper.Map <LicenseResponseModel>(licenseDataModel);

            return(CreatedAtAction(nameof(GetLicenseResponse), new { id = licenseResponse.Id }, licenseResponse));
        }
Beispiel #3
0
        public async Task PostLicense(LicenseRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            var license = await ApiHelpers.ReadJsonFileFromBody <UserLicense>(HttpContext, model.License);

            if (license == null)
            {
                throw new BadRequestException("Invalid license");
            }

            await _userService.UpdateLicenseAsync(user, license);
        }
Beispiel #4
0
        public async Task PostLicense(string id, LicenseRequestModel model)
        {
            var orgIdGuid = new Guid(id);

            if (!_currentContext.OrganizationOwner(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var license = await ApiHelpers.ReadJsonFileFromBody <OrganizationLicense>(HttpContext, model.License);

            if (license == null)
            {
                throw new BadRequestException("Invalid license");
            }

            await _organizationService.UpdateLicenseAsync(new Guid(id), license);
        }