public void InsertNewImageElement_ShouldReturnNull_SameUri() { //Arrange var fakeDatabaseImageElementList = new List <DatabaseImageElement>() { new DatabaseImageElement() { Id = 1, ImageName = "testImageName", ImageContentUri = "https://whoisthatserverimages.blob.core.windows.net/images/Domantas_test.jpg", PersonFirstName = "testFirstPersonName", PersonLastName = "testFirstPersonLastName", DescriptiveSentence = "t1", Score = 1 } }; var fakeDbSet = UnitTestsUtil.SetupFakeDbSet(fakeDatabaseImageElementList.AsQueryable()); var fakeDatabaseContext = A.Fake <DatabaseContext>(); A.CallTo(() => fakeDatabaseContext.DatabaseImageElements) .Returns(fakeDbSet); var fakeDbContextGeneration = A.Fake <IDatabaseContextGeneration>(); A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()) .Returns(fakeDatabaseContext); var databaseImageElementHelper = new DatabaseImageElementHelper(fakeDbContextGeneration); //Act var expectedId = 1; var expectedImageName = "testImageName"; var expectedImageContentUri = "https://whoisthatserverimages.blob.core.windows.net/images/Domantas_test.jpg"; var expectedPersonFirstName = "testPersonFirstName"; var expectedPersonLastName = "testPersonLastName"; var expectedDescriptiveSentence = "t1"; var exptectedScore = 1; var result = databaseImageElementHelper.InsertNewImageElement(expectedId, expectedImageName, expectedImageContentUri, expectedPersonFirstName, expectedPersonLastName, expectedDescriptiveSentence, exptectedScore); //Assert A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).MustHaveHappened(); result.ShouldBe(null); }
public void InsertNewImageElement_ShouldThrow_BadUri() { //Arrange var fakeDatabaseImageElementList = new List <DatabaseImageElement>() { new DatabaseImageElement() { Id = 1, ImageName = "testImageName", ImageContentUri = "https://whoisthatserverimages.blob.core.windows.net/images/Domantas_test.jpg", PersonFirstName = "testFirstPersonName", PersonLastName = "testFirstPersonLastName", DescriptiveSentence = "t1", Score = 1 } }; var fakeDbSet = UnitTestsUtil.SetupFakeDbSet(fakeDatabaseImageElementList.AsQueryable()); var fakeDatabaseContext = A.Fake <DatabaseContext>(); A.CallTo(() => fakeDatabaseContext.DatabaseImageElements) .Returns(fakeDbSet); var fakeDbContextGeneration = A.Fake <IDatabaseContextGeneration>(); A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()) .Returns(fakeDatabaseContext); var databaseImageElementHelper = new DatabaseImageElementHelper(fakeDbContextGeneration); //Act and assert Assert.Throws <ManagerException>(() => databaseImageElementHelper.InsertNewImageElement(1, "test", "invalidURI", "test", "test", "t1", 1), StorageErrorMessages.InvalidImageUriError); A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).MustNotHaveHappened(); }
public IHttpActionResult Post([FromBody] DatabaseImageElement databaseImageElement) { try { databaseImageElement = DatabaseImageElementHelper.InsertNewImageElement(databaseImageElement.Id, databaseImageElement.ImageName, databaseImageElement.ImageContentUri, databaseImageElement.PersonFirstName, databaseImageElement.PersonLastName, databaseImageElement.DescriptiveSentence, databaseImageElement.Score); return(Json(databaseImageElement)); } catch (ManagerException wrongUriException) when(wrongUriException.ErrorCode == StorageErrorMessages.InvalidImageUriError) { return(BadRequest(StorageErrorMessages.InvalidImageUriError)); } catch (ManagerException wrongFilenameException) when(wrongFilenameException.ErrorCode == StorageErrorMessages.InvalidFileNameError) { return(BadRequest(StorageErrorMessages.InvalidFileNameError)); } }