Exemplo n.º 1
0
        public void WhenGetUserListRootObject_ShouldReturnValidRootObjectList()
        {
            //Set up
            Mock <IJsonFileDataService> mockJsonHelper      = GetMockJsonHelperSetUp();
            Mock <IFilePathService>     mockFilePathService = GetMockFilePathServiceSetup();

            //Act
            GetUsersService   gUserServ          = new GetUsersService(mockJsonHelper.Object, mockFilePathService.Object);
            AllUsersRootModel userListRootObject = gUserServ.GetUserListRootObject();
            bool expectedItemValidCount          = userListRootObject.users.Count() == 7;

            IEnumerable <UserModel> allUsers    = userListRootObject.users;
            string actualFirstPersonFirstName   = allUsers.FirstOrDefault().FirstName;
            string expectedFirstPersonFirstName = "brad";

            //Assert
            Assert.True(expectedItemValidCount, "Item count does not match the expected count (7).");
            actualFirstPersonFirstName.ShouldBe(expectedFirstPersonFirstName, "First name of the first person " +
                                                $"on the list is not {expectedFirstPersonFirstName}.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get users list
        /// </summary>
        /// <returns>List of users</returns>
        public IEnumerable <UserModel> GetUserLists()
        {
            AllUsersRootModel userListsob = GetUserListRootObject();

            return(userListsob.users);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Serialize data into Json format then save that data onto a Json File.
        /// </summary>
        /// <param name="userListsRootOb">All Users List from the root object level</param>
        /// <param name="filePathToData">File path to get the Json file providing user data</param>
        public void SerializedDataAndSavetoJsonFile(AllUsersRootModel userListsRootOb, string filePathToData)
        {
            var serializedUserLists = JsonConvert.SerializeObject(userListsRootOb, Formatting.Indented);

            File.WriteAllText(filePathToData, serializedUserLists);
        }