Example #1
0
        public void GetFaceFeaturesByPersonId_WhenIdExists_ShouldReturn()
        {
            //Arrange
            var expectedId       = 0;
            var expectedPersonId = 1;
            var expectedAge      = 20;
            var expectedGender   = "male";

            var fakeIQueryable = new List <FaceFeaturesModel>()
            {
                new FaceFeaturesModel()
                {
                    Id       = expectedId,
                    PersonId = expectedPersonId,
                    Age      = expectedAge,
                    Gender   = expectedGender
                }
            }.AsQueryable();

            var fakeDbSet = UnitTestsUtil.SetupFakeDbSet(fakeIQueryable);

            var fakeDbContext = A.Fake <DatabaseContext>();

            A.CallTo(() => fakeDbContext.FaceFeatures).Returns(fakeDbSet);

            var fakeDbContextGeneration = A.Fake <IDatabaseContextGeneration>();

            A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).Returns(fakeDbContext);

            var faceFeaturesHelper = new FaceFeaturesHelper(fakeDbContextGeneration);

            //Act
            var result = faceFeaturesHelper.GetFaceFeaturesByPersonId(expectedPersonId);

            //Assert
            A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).MustHaveHappenedOnceExactly();

            result.Id.ShouldBe(expectedId);
            result.Age.ShouldBe(expectedAge);
            result.Gender.ShouldBe(expectedGender);
            result.PersonId.ShouldBe(expectedPersonId);
        }
Example #2
0
        public void GetFaceFeaturesByPersonId_WhenIdDoesNotExists_ShouldThrow()
        {
            //Arrange
            var expectedId       = 0;
            var expectedPersonId = 1;
            var expectedAge      = 20;
            var expectedGender   = "male";

            var fakeIQueryable = new List <FaceFeaturesModel>()
            {
                new FaceFeaturesModel()
                {
                    Id       = expectedId,
                    PersonId = expectedPersonId,
                    Age      = expectedAge,
                    Gender   = expectedGender
                }
            }.AsQueryable();

            var fakeDbSet = UnitTestsUtil.SetupFakeDbSet(fakeIQueryable);

            var fakeDbContext = A.Fake <DatabaseContext>();

            A.CallTo(() => fakeDbContext.FaceFeatures).Returns(fakeDbSet);

            var fakeDbContextGeneration = A.Fake <IDatabaseContextGeneration>();

            A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).Returns(fakeDbContext);

            var faceFeaturesHelper = new FaceFeaturesHelper(fakeDbContextGeneration);

            //Act and assert
            Assert.Throws <ManagerException>(() => faceFeaturesHelper.GetFaceFeaturesByPersonId(100),
                                             StorageErrorMessages.UserDoesNotExistError);

            A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).MustHaveHappenedOnceExactly();
        }