Exemple #1
0
        public void PutWithInvalidIdShouldReturnNotFoundResult()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var result = controller.Put(TestConstants.DefaultNonExistingModelId, true);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Exemple #2
0
        public void GetShouldReturnOkResultWithData()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var result = controller.Get();

            var expected = TestConstants.DefaultPageSize;
            var actual   = result as OkNegotiatedContentResult <List <PhotoResponseModel> >;

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected, actual.Content.Count);
        }
Exemple #3
0
        public void GetWithIdShouldReturnOkResultWithData()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var result = controller.Get(0);

            var actual        = result as OkNegotiatedContentResult <PhotoResponseModel>;
            var expectedTitle = TestConstants.ValidTitle;


            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedTitle, actual.Content.Title);
        }
Exemple #4
0
        public void DeleteWithInvalidIdShouldReturnNotFoundResult()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var result = controller.Delete(TestConstants.DefaultNonExistingModelId);
            var expectedNumberOfPhotos = TestConstants.DefaultNumberOfModels;
            var expectedSaveChanges    = 0;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
            Assert.AreEqual(expectedNumberOfPhotos, this.photos.NumberOfModels);
            Assert.AreEqual(expectedSaveChanges, this.photos.NumberOfSaves);
        }
Exemple #5
0
        public void DeleteWithValidIdShouldReturnOkResult()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var result = controller.Delete(0);
            var actual = result as OkNegotiatedContentResult <string>;
            var expectedNumberOfPhotos = TestConstants.DefaultNumberOfModels - 1;
            var expectedSaveChanges    = 1;
            var expectedMessage        = "Photo deleted";

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedMessage, actual.Content);
            Assert.AreEqual(expectedNumberOfPhotos, this.photos.NumberOfModels);
            Assert.AreEqual(expectedSaveChanges, this.photos.NumberOfSaves);
        }
Exemple #6
0
        public void PostWithInvalidModelStateShouldReturnInvalidModelStateResult()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            controller.ModelState.AddModelError("url", "Invalid url!");

            var photo  = new PhotoRequestModel();
            var result = controller.Post(photo);
            var expectedSaveChanges    = 0;
            var expectedNumberOfPhotos = TestConstants.DefaultNumberOfModels;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult));
            Assert.AreEqual(expectedNumberOfPhotos, this.photos.NumberOfModels);
            Assert.AreEqual(expectedSaveChanges, this.photos.NumberOfSaves);
        }
Exemple #7
0
        public void PostWithInvalidAlbumIdShouldReturnNotFoundResult()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var photo = new PhotoRequestModel
            {
                Title         = TestConstants.ValidTitle,
                ImageUrl      = TestConstants.ValidUrl,
                FileExtension = TestConstants.ValidFileExtension,
                AlbumId       = TestConstants.DefaultNonExistingModelId
            };
            var result = controller.Post(photo);
            var expectedSaveChanges    = 0;
            var expectedNumberOfPhotos = TestConstants.DefaultNumberOfModels;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
            Assert.AreEqual(expectedNumberOfPhotos, this.photos.NumberOfModels);
            Assert.AreEqual(expectedSaveChanges, this.photos.NumberOfSaves);
        }
Exemple #8
0
        public void PostWithValidDataShouldReturnOkResult()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var photo = new PhotoRequestModel
            {
                Title         = TestConstants.ValidTitle,
                ImageUrl      = TestConstants.ValidUrl,
                FileExtension = TestConstants.ValidFileExtension,
                AlbumId       = 0
            };
            var result = controller.Post(photo);
            var expectedNumberOfPhotos = 16;
            var expectedSaveChanges    = 1;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <int>));
            Assert.AreEqual(expectedNumberOfPhotos, this.photos.NumberOfModels);
            Assert.AreEqual(expectedSaveChanges, this.photos.NumberOfSaves);
        }
Exemple #9
0
        public void PutWithValidDataShouldReturnOkResult()
        {
            var controller = ControllerMockFactory.GetPhotosController(this.photos, this.albums);

            var result          = controller.Put(0, true);
            var expectedContent = "Successfully liked picture!";
            var expectedLikes   = 1;
            var actual          = result as OkNegotiatedContentResult <string>;

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedContent, actual.Content);
            Assert.AreEqual(expectedLikes, this.photos.GetById(0).Likes);

            result          = controller.Put(0, false);
            expectedContent = "Successfully disliked picture!";
            expectedLikes   = 0;
            actual          = result as OkNegotiatedContentResult <string>;

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedContent, actual.Content);
            Assert.AreEqual(expectedLikes, this.photos.GetById(0).Likes);
        }