Beispiel #1
0
        public void ShouldCallScreenshotRepositoryCollection()
        {
            const int screenshotId = 7;

            _mockedScreenshotRepository.SetupGet(sr => sr.Collection)
            .Returns(new[] { new Screenshot {
                                 Id = screenshotId
                             } }.AsQueryable())
            .Verifiable("ScreenshotRepository's Collection should have been retrieved.");

            _screenshotDeleter.DeleteScreenshot(screenshotId);

            _mockedScreenshotRepository.VerifyGet(sr => sr.Collection, Times.AtMost(2));
        }
Beispiel #2
0
        public void Delete(string key, string id)
        {
            ValidateInputs(() => _serviceInputValidator.ValidateUserApiKey(key));
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new WebFaultException <string>("A Screenshot ID is required.", HttpStatusCode.BadRequest);
            }
            int idOfScreenshotToDelete;

            if (!int.TryParse(id, out idOfScreenshotToDelete))
            {
                throw new WebFaultException <string>(string.Format("A malformed Screenshot ID was given. '{0}' is not valid.", id), HttpStatusCode.BadRequest);
            }
            Screenshot screenshotToDelete = _screenshotRepository.Collection.SingleOrDefault(s => s.Id == idOfScreenshotToDelete);

            if (screenshotToDelete == null)
            {
                throw new WebFaultException <string>("The specified Screenshot does not exist.", HttpStatusCode.BadRequest);
            }
            Action deleteScreenshotAction = () =>
            {
                _packageAuthenticator.EnsureKeyCanAccessPackage(key, screenshotToDelete.PackageId, screenshotToDelete.PackageVersion);
                _screenshotDeleter.DeleteScreenshot(idOfScreenshotToDelete);
            };

            ExecuteAction(deleteScreenshotAction, "The Screenshot could not be deleted");
        }