예제 #1
0
        public void TestCannotViewPrivateUser()
        {
            var users        = FakeUsers.Get().AsQueryable().Where(u => u.ProfileVisibility == Visibility.Hidden);
            var visibleUsers = users.CanViewUsers(FakeUsers.GetPublic().AsModel());

            visibleUsers.Should().HaveCount(0);
        }
예제 #2
0
        public async Task TestGetPlantInfoAsync()
        {
            var plantInfoService = new PlantInfoService(_mockPlantInfoRepository.Object, _mockPlantLocationRepository.Object, _mockPlantInfoIndex.Object);
            var plantInfo        = await plantInfoService.GetPlantInfoAsync(1, FakeUsers.GetPublic().AsModel());

            plantInfo.Should().NotBeNull("it exists");
        }
예제 #3
0
        public async Task TestGetSpecimenAsync()
        {
            var specimenService = new SpecimenService(_mockSpecimenRepository.Object, _mockSpecimenIndex.Object);
            var specimen        = await specimenService.GetSpecimenAsync(1, FakeUsers.GetPublic().AsModel());

            specimen.Should().NotBeNull("it exists");
        }
예제 #4
0
        public static void CreateSeedData(IDocumentStore documentStore)
        {
            Condition.Requires(documentStore).IsNotNull();

            using (IDocumentSession documentSession = documentStore.OpenSession())
            {
                // First, check to make sure we don't have any data.
                var user = documentSession.Load <User>(1);
                if (user != null)
                {
                    // ooOooo! we have a user, so it's assumed we actually have some seeded data.
                    return;
                }

                // We have no users, so it's assumed we therefore have no data at all.
                // So lets fake some up :)

                // Users.
                ICollection <User> users = FakeUsers.CreateFakeUsers(50);
                StoreFakeEntities(users, documentSession);

                // Questions.
                ICollection <Question> questions = FakeQuestions.CreateFakeQuestions(users.Select(x => x.Id).ToList());
                StoreFakeEntities(questions, documentSession);

                documentSession.SaveChanges();

                // Make sure all our indexes are not stale.
                documentStore.WaitForStaleIndexesToComplete();
            }
        }
        public void TestCanViewSpecimen()
        {
            var specimens        = FakeSpecimens.Get().AsQueryable <Specimen>();
            var visibleSpecimens = specimens.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleSpecimens.Should().HaveCount(2);
        }
예제 #6
0
        public void TestCanViewInventoryItems()
        {
            var inventoryItems        = FakeInventories.GetItems().AsQueryable();
            var visibleInventoryItems = inventoryItems.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleInventoryItems.Should().HaveCount(2);
        }
예제 #7
0
        public void TestCanViewUser()
        {
            var users        = FakeUsers.Get().AsQueryable();
            var visibleUsers = users.CanViewUsers(FakeUsers.GetPublic().AsModel());

            visibleUsers.Should().HaveCount(2);
        }
예제 #8
0
        public void TestCanViewPlantInfos()
        {
            var plantInfos        = FakePlantInfos.Get().AsQueryable();
            var visiblePlantInfos = plantInfos.CanViewContent(FakeUsers.GetPublic().AsModel());

            visiblePlantInfos.Should().HaveCount(2);
        }
예제 #9
0
        public void TestCanViewActivities()
        {
            var activities        = FakeActivities.Get().AsQueryable();
            var visibleActivities = activities.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleActivities.Should().HaveCount(3);
        }
예제 #10
0
        public void TestCanViewOrigins()
        {
            var origins        = FakeOrigins.Get().AsQueryable();
            var visibleOrigins = origins.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleOrigins.Should().HaveCount(1);
        }
예제 #11
0
        public static Mock <IUserService> GetStandardMockUserService(IEnumerable <User> result = null)
        {
            if (result == null)
            {
                result = FakeUsers.Get().Select(u => u.AsModel());
            }

            var mockUserService = new Mock <IUserService>();

            mockUserService.Setup(u => u.GetIdentifyingUser(It.IsAny <string>()))
            .ReturnsAsync((string userId) => result.FirstOrDefault(u => u.UserId == userId));

            mockUserService.Setup(u => u.GetUserAsync(It.IsAny <string>()))
            .ReturnsAsync((string userId) => result.FirstOrDefault(u => u.UserId == userId));

            mockUserService.Setup(u => u.GetUserByNameAsync(It.IsAny <string>(), It.IsAny <User>()))
            .ReturnsAsync((string name) => result.FirstOrDefault(u => u.DisplayName == name));

            mockUserService.Setup(u => u.GetUserIdAsync(It.IsAny <string>()))
            .ReturnsAsync((string userId) => result.FirstOrDefault(u => u.UserId == userId).Id);

            mockUserService.Setup(u => u.GetRandomNameAsync())
            .ReturnsAsync("ElatedScurfpea");

            mockUserService.Setup(u => u.AddUserAsync(It.IsAny <User>()))
            .ReturnsAsync((User user) => user);

            mockUserService.Setup(u => u.UpdateUserAsync(It.IsAny <User>()))
            .ReturnsAsync((User user) => user);

            return(mockUserService);
        }
예제 #12
0
        public void TestCannotViewContactUser()
        {
            var users = new List <User> {
                FakeUsers.GetContact()
            }.AsQueryable();
            var visibleUsers = users.CanViewUsers(FakeUsers.GetPrivate().AsModel());

            visibleUsers.Should().HaveCount(0);
        }
        public async Task TestGetUserContactStatusAsync()
        {
            var userContactService = new UserContactService(_mockUserContactRepository.Object, _mockUserContactRequestRepository.Object);
            var requestor          = FakeUsers.GetPublic().AsModel();
            var user = FakeUsers.GetContact().AsModel();
            var userContactStatus = await userContactService.GetUserContactStatusAsync(requestor, user);

            userContactStatus.Contacts.Count(c => c.UserId == requestor.Id).Should().Be(1);
        }
예제 #14
0
        public void TestCannotViewHiddenInventoryItem()
        {
            var inventoryItems = new List <InventoryItem>
            {
                new InventoryItem
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden
                }
            }.AsQueryable();

            var visibleInventoryItems = inventoryItems.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleInventoryItems.Should().HaveCount(0);
        }
예제 #15
0
        public void TestCannotViewHiddenActivity()
        {
            var activities = new List <Activity>
            {
                new Activity
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden
                }
            }.AsQueryable();

            var visibleActivities = activities.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleActivities.Should().HaveCount(0);
        }
예제 #16
0
        public void TestCannotViewHiddenOrigin()
        {
            var origins = new List <Origin>
            {
                new Origin
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden
                }
            }.AsQueryable();

            var visibleOrigins = origins.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleOrigins.Should().HaveCount(0);
        }
예제 #17
0
        public void TestCannotViewHiddenPlantInfo()
        {
            var plantInfos = new List <PlantInfo>
            {
                new PlantInfo
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden,
                    User       = new User()
                }
            }.AsQueryable();

            var visiblePlantInfos = plantInfos.CanViewContent(FakeUsers.GetPublic().AsModel());

            visiblePlantInfos.Should().HaveCount(0);
        }
예제 #18
0
        public void TestCanViewOwnHiddenInventoryItem()
        {
            var inventoryItems = new List <InventoryItem>
            {
                new InventoryItem
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden,
                    User       = FakeUsers.GetPrivate(),
                    UserId     = FakeUsers.GetPrivate().Id
                }
            }.AsQueryable();

            var visibleInventoryItems = inventoryItems.CanViewContent(FakeUsers.GetPrivate().AsModel());

            visibleInventoryItems.Should().HaveCount(1);
        }
예제 #19
0
        public void TestCanViewOwnHiddenPlantInfo()
        {
            var plantInfos = new List <PlantInfo>
            {
                new PlantInfo
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden,
                    User       = FakeUsers.GetPrivate(),
                    UserId     = FakeUsers.GetPrivate().Id
                }
            }.AsQueryable();

            var visiblePlantInfos = plantInfos.CanViewContent(FakeUsers.GetPrivate().AsModel());

            visiblePlantInfos.Should().HaveCount(1);
        }
예제 #20
0
        public void TestCanViewOwnHiddenOrigin()
        {
            var origins = new List <Origin>
            {
                new Origin
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden,
                    User       = FakeUsers.GetPrivate(),
                    UserId     = FakeUsers.GetPrivate().Id
                }
            }.AsQueryable();

            var visibleOrigins = origins.CanViewContent(FakeUsers.GetPrivate().AsModel());

            visibleOrigins.Should().HaveCount(1);
        }
예제 #21
0
        public void TestCanViewOwnHiddenActivity()
        {
            var activities = new List <Activity>
            {
                new Activity
                {
                    Id         = 1,
                    Visibility = Visibility.Hidden,
                    User       = FakeUsers.GetPrivate(),
                    UserId     = FakeUsers.GetPrivate().Id
                }
            }.AsQueryable();

            var visibleActivities = activities.CanViewContent(FakeUsers.GetPrivate().AsModel());

            visibleActivities.Should().HaveCount(1);
        }
예제 #22
0
            public void GivenSomeQuestionsAndNoDisplayNameAndNoTags_Index_ReturnsAJsonViewOfMostRecentQuestions()
            {
                // Arrange.
                DataToBeSeeded = new List <IEnumerable>
                {
                    FakeQuestions.CreateFakeQuestions(new[] { "users/1", "users/2", "users/3" }),
                    FakeUsers.CreateFakeUsers()
                };
                IndexesToExecute = new List <Type> {
                    typeof(Questions_Search)
                };

                var homeController = new HomeController(DocumentSession, new CustomFormsAuthentication());

                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                // Note: this should return a list of the 20 most recent.
                JsonResult result = homeController.IndexJson(null, null);

                // Assert.
                Assert.NotNull(result);
                var questions = result.Data as IList <QuestionWithDisplayName>;

                Assert.NotNull(questions);
                Assert.Equal(20, questions.Count);

                // Now lets Make sure each one is ok.
                DateTime?previousDate = null;

                foreach (QuestionWithDisplayName question in questions)
                {
                    if (previousDate.HasValue)
                    {
                        Assert.True(previousDate.Value > question.CreatedOn);
                    }

                    previousDate = question.CreatedOn;
                    Assert.NotNull(question.DisplayName);
                    Assert.NotNull(question.Id);
                    Assert.NotNull(question.CreatedByUserId);
                    Assert.NotNull(question.Subject);
                    Assert.NotNull(question.Content);
                }
            }
예제 #23
0
        public void TestCanViewInventoryItemInheritPublic()
        {
            var inventoryItems = new List <InventoryItem>
            {
                new InventoryItem
                {
                    Id   = 1,
                    User = new User
                    {
                        ProfileVisibility = Visibility.Public
                    }
                }
            }.AsQueryable();

            var visibleInventoryItems = inventoryItems.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleInventoryItems.Should().HaveCount(1);
        }
예제 #24
0
        private static void CreateSeedData(IDocumentStore documentStore)
        {
            Condition.Requires(documentStore).IsNotNull();

            // Users.
            ICollection <User> users = FakeUsers.CreateFakeUsers(50);

            // Questions.
            ICollection <Question> questions = FakeQuestions.CreateFakeQuestions(users.Select(x => x.Id).ToList());

            using (IDocumentSession documentSession = documentStore.OpenSession())
            {
                StoreFakeEntities(users, documentSession);
                StoreFakeEntities(questions, documentSession);

                documentSession.SaveChanges();
            }
        }
예제 #25
0
        public void TestCanViewPlantInfoInheritPublic()
        {
            var plantInfos = new List <PlantInfo>
            {
                new PlantInfo
                {
                    Id   = 1,
                    User = new User
                    {
                        ProfileVisibility = Visibility.Public
                    }
                }
            }.AsQueryable();

            var visiblePlantInfos = plantInfos.CanViewContent(FakeUsers.GetPublic().AsModel());

            visiblePlantInfos.Should().HaveCount(1);
        }
예제 #26
0
        public async Task TestFindOrigins()
        {
            var mockOriginRepository = RepositoryMocks.GetStandardMockOriginRepository(Data.Fakes.Stores.FakeOrigins.Get().Where(o => o.Name == "Botany Yards"));

            var originService = new OriginService(mockOriginRepository.Object, _mockLocationService.Object);
            var origins       = await originService.FindOrigins(new FindParams
            {
                SearchText    = "Botany",
                Skip          = 0,
                Take          = 10,
                SortBy        = "",
                SortDirection = SortDirection.None
            }, FakeUsers.GetPublic().AsModel());

            origins.Results.Should().NotBeNull("it exists");
            origins.Results.Should().HaveCount(1);
            origins.Results.Where(o => o.Visibility == Visibility.Public).Should().HaveCount(1);
        }
예제 #27
0
        public void TestCanViewOriginInheritPublic()
        {
            var origins = new List <Origin>
            {
                new Origin
                {
                    Id   = 1,
                    User = new User
                    {
                        ProfileVisibility = Visibility.Public
                    }
                }
            }.AsQueryable();

            var visibleOrigins = origins.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleOrigins.Should().HaveCount(1);
        }
예제 #28
0
        public async Task TestFindPlantInfosAsync()
        {
            var plantInfoService = new PlantInfoService(_mockPlantInfoRepository.Object, _mockPlantLocationRepository.Object, _mockPlantInfoIndex.Object);

            var plantInfoResult = await plantInfoService.FindPlantInfos(new PlantInfoFindParams
            {
                SearchText    = "Liatris spicata",
                Skip          = 0,
                Take          = 10,
                SortBy        = "",
                SortDirection = SortDirection.None
            },
                                                                        FakeUsers.GetPublic().AsModel());

            plantInfoResult.Results.Should().NotBeNull("it exists");
            plantInfoResult.Count.Should().Be(2);
            plantInfoResult.Results.Should().HaveCount(2);
        }
        public void TestCannotViewHiddenSpecimen()
        {
            var specimens = new List <Specimen>
            {
                new Specimen
                {
                    Id            = 1,
                    InventoryItem = new InventoryItem
                    {
                        Id         = 1,
                        Visibility = Visibility.Hidden
                    }
                }
            }.AsQueryable();

            var visibleSpecimens = specimens.CanViewContent(FakeUsers.GetPublic().AsModel());

            visibleSpecimens.Should().HaveCount(0);
        }
        public void UserValidateServiceLastNameOfUserIsNullOrEmptyTest()
        {
            // Arrange
            var fakerNewUsers = new FakeUsers(
                usersCount: 1,
                isFirstNameNullOrEmpty: false,
                isLastNameNullOrEmpty: true,
                isLoginNullOrEmpty: false,
                isPasswordNullOrEmpty: false,
                minLoginLenght: 5,
                minPasswordLenght: 5);

            // Act
            var resultUserValidationBeforRegistration =
                _userValidateService.UserValidateOnAddition(fakerNewUsers.Users[0]);

            // Assert
            resultUserValidationBeforRegistration.Should().BeFalse();
        }
        public void TestCreatePostThrowsExceptionWhenUserNotFound()
        {
            var thisFar = false;
            try
            {
                #region Arrange
                Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "NotFound");
                var fakeUsers = new FakeUsers();
                fakeUsers.Records(3, UserRepository);
                #endregion Arrange

                #region Act
                thisFar = true;
                Controller.Create(99);
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("Sequence contains no elements", ex.Message);
                throw;
            }
        }