public async Task AddProfileReturns503WhenStorageIsDown()
        {
            var profilesStoreMock = new Mock <IProfileStore>();

            profilesStoreMock.Setup(store => store.AddProfile(_testProfile)).ThrowsAsync(new StorageErrorException());
            var           loggerStub = new ProfilesControllerLoggerStub();
            var           controller = new ProfileController(profilesStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.Post(_testProfile);

            AssertUtils.HasStatusCode(HttpStatusCode.ServiceUnavailable, result);
            Assert.Contains(LogLevel.Error, loggerStub.LogEntries.Select(entry => entry.Level));
        }
        public async Task GetProfileReturns500WhenExceptionIsNotKnown()
        {
            var profilesStoreMock = new Mock <IProfileStore>();

            profilesStoreMock.Setup(store => store.GetProfile(_testProfile.Username)).ThrowsAsync(new Exception("Test Exception"));
            var           loggerStub = new ProfilesControllerLoggerStub();
            var           controller = new ProfileController(profilesStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.Get(_testProfile.Username);

            AssertUtils.HasStatusCode(HttpStatusCode.InternalServerError, result);
            Assert.Contains(LogLevel.Error, loggerStub.LogEntries.Select(entry => entry.Level));
        }
        public async Task UpdateProfileReturn503WhenOptimisticConcurrencyFails()
        {
            var profilesStoreMock = new Mock <IProfileStore>();

            profilesStoreMock.Setup(store => store.UpdateProfile(_testProfile)).ThrowsAsync(new StorageConflictException());
            var           loggerStub = new ProfilesControllerLoggerStub();
            var           controller = new ProfileController(profilesStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.Put(_testProfile.Username, new UpdateProfileRequestBody()
            {
                Firstname = _testProfile.Firstname, Lastname = _testProfile.Lastname
            });

            AssertUtils.HasStatusCode(HttpStatusCode.ServiceUnavailable, result);
            Assert.Contains(LogLevel.Error, loggerStub.LogEntries.Select(entry => entry.Level));
        }