Exemplo n.º 1
0
        public async Task AddGetProfile()
        {
            await _profileStore.AddProfile(_profile);

            var storedProfile = await _profileStore.GetProfile(_profile.Username);

            Assert.Equal(_profile, storedProfile);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] Profile profile)
        {
            using (_logger.BeginScope("{Username}", profile.Username))
            {
                if (!ValidateProfile(profile, out string error))
                {
                    return(BadRequest(error));
                }

                try
                {
                    var stopWatch = Stopwatch.StartNew();
                    await _profileStore.AddProfile(profile);

                    _telemetryClient.TrackMetric("ProfileStore.AddProfile.Time", stopWatch.ElapsedMilliseconds);
                    _telemetryClient.TrackEvent("ProfileAdded");
                    return(CreatedAtAction(nameof(Get), new { username = profile.Username }, profile));
                }
                catch (ProfileAlreadyExistsException e)
                {
                    _logger.LogError(e, $"Profile {profile.Username} already exists in storage");
                    return(Conflict($"Profile {profile.Username} already exists"));
                }
                catch (StorageErrorException e)
                {
                    _logger.LogError(e, $"Failed add profile {profile} to storage");
                    return(StatusCode(503, "The service is unavailable, please retry in few minutes"));
                }
                catch (Exception e)
                {
                    _logger.LogError(e, $"Unknown exception occured while adding profile {profile} to storage");
                    return(StatusCode(500, "An internal server error occured, please reachout to support if this error persists"));
                }
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateProfile([FromBody] CreateProfileDto request)
        {
            var profile = new UserProfile(request.Username, request.FirstName, request.LastName);

            try
            {
                await profileStore.AddProfile(profile);

                logger.LogInformation(Events.ProfileCreated, "A Profile has been added for user {username}",
                                      request.Username);
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Failed to create a profile for user {username}", request.Username);
                return(StatusCode(503, "Failed to reach storage"));
            }
            catch (DuplicateProfileException)
            {
                logger.LogInformation(Events.ProfileAlreadyExists,
                                      "The profile for user {username} cannot be created because it already exists",
                                      request.Username);
                return(StatusCode(409, "Profile already exists"));
            }
            catch (ArgumentException)
            {
                return(StatusCode(400, "Invalid or incomplete Request Body"));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to create a profile for user {username}", request.Username);
                return(StatusCode(500, "Failed to create profile"));
            }
            return(Created(request.Username, profile));
        }
Exemplo n.º 4
0
        public async Task AddProfile(UserProfile profile)
        {
            using (_logger.BeginScope("{Username}", profile.Username))
            {
                if (!ValidateProfile(profile, out string error))
                {
                    throw new BadRequestException(error);
                }
                var stopWatch = Stopwatch.StartNew();
                await _profileStore.AddProfile(profile);

                _telemetryClient.TrackMetric("ProfileStore.AddProfile.Time", stopWatch.ElapsedMilliseconds);
                _telemetryClient.TrackEvent("ProfileCreated");
            }
        }
 public Task AddProfile(UserProfile profile)
 {
     return(faultTolerancePolicy.Execute(
                async() => await store.AddProfile(profile)
                ));
 }
Exemplo n.º 6
0
 public Task AddProfile(UserProfile profile)
 {
     return(addProfileMetric.TrackTime(() => store.AddProfile(profile)));
 }
 public async Task AddProfile(UserProfile profile)
 {
     await resiliencyPolicy.ExecuteAsync(() => profileStore.AddProfile(profile));
 }
Exemplo n.º 8
0
 public Task AddProfile(Profile profile)
 {
     return(_profileStore.AddProfile(profile));
 }