Exemple #1
0
        public void CharacterRepository_Save()
        {
            //seed a character
            var character = _repoHelper.SeedCharacters().First();

            //keep a local copy of the character name
            var characterInitName = character.Name;

            //modify the character
            character.Name = Guid.NewGuid().ToString();

            //keep a local copy of the new character name
            var characterModName = character.Name;

            //save the character with the new name
            _characterRepo.Save(character);

            //get the character from the db
            var characterDb = _characterRepo.Get(character.Id);

            //ensure the init name isn't the same as the db name
            Assert.AreNotEqual(characterInitName, characterDb.Name);

            //ensure the mod name is the same as the db name
            Assert.AreEqual(characterModName, characterDb.Name);

            //ensure the db returns what we gave it
            var comparer = new PropertyComparer <Character>();

            Assert.IsTrue(comparer.Equals(character, characterDb));
        }
Exemple #2
0
        public void compare_two_string_by_length_using_equals()
        {
            const string string1  = "lorem";
            const string string2  = "ipsum";
            var          comparer = new PropertyComparer <string>(x => x.Length);

            Assert.True(comparer.Equals(string1, string2));
        }
        public void compare_two_string_by_length_using_equals()
        {
            const string string1 = "lorem";
            const string string2 = "ipsum";
            var comparer = new PropertyComparer<string>(x => x.Length);

            Assert.True(comparer.Equals(string1, string2));
        }
Exemple #4
0
        public void CharacterRepository_Get()
        {
            //seed a character
            var character = _repoHelper.SeedCharacters().First();

            //get the character
            var characterDb = _characterRepo.Get(character.Id);

            //check to see if the db returns what we gave it
            var comparer = new PropertyComparer <Character>();

            Assert.IsTrue(comparer.Equals(character, characterDb));
        }
Exemple #5
0
        public void StoryRepository_Get()
        {
            //seed a story
            var story = _repoHelper.SeedStories().First();

            //get the story
            var storyDb = _storyRepo.Get(story.Id);

            //check to see if the db returns what we gave it
            var comparer = new PropertyComparer <Story>();

            Assert.IsTrue(comparer.Equals(story, storyDb));
        }
Exemple #6
0
        public void CharacterRepository_New()
        {
            //seed a story
            var story = _repoHelper.SeedStories().First();

            //create a character
            var character = new Character
            {
                Name  = Guid.NewGuid().ToString(),
                Story = story
            };

            //save the character
            _characterRepo.Save(character);

            //get the character from the db
            var characterDb = _characterRepo.Get(character.Id);

            //ensure the db returns what we gave it
            var comparer = new PropertyComparer <Character>();

            Assert.IsTrue(comparer.Equals(character, characterDb));
        }
        public void HomeController_Index()
        {
            //controller instance with dependency injection
            var controller = new HomeController(_storyRepo);

            //fire the index action
            var result = controller.Index() as ViewResult;

            //ensure we get something back
            Assert.IsNotNull(result);

            //ensure result is a ViewResult
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            var viewResult = result as ViewResult;

            //ensure viewResult is the index view
            Assert.AreEqual("Index", viewResult.ViewName);

            //ensure the model is a story collection
            Assert.IsInstanceOfType(viewResult.Model, typeof(List <StoryModel>));

            var model = viewResult.Model as List <StoryModel>;

            //ensure the model matches our mock
            Assert.AreEqual(_stories.Count, model.Count);

            var comparer    = new PropertyComparer <StoryModel>();
            var storyModels = Mapper.Map <List <Story>, List <StoryModel> >(_stories);

            foreach (var modelItem in model)
            {
                var mockItem = storyModels.Single(x => x.Id == modelItem.Id);

                Assert.IsTrue(comparer.Equals(modelItem, mockItem));
            }
        }
 /// <summary>
 /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>    
 public override bool Equals(object obj)
 {
     var comparer = new PropertyComparer();
       return comparer.Equals(this, obj);
 }
Exemple #9
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            var comparer = new PropertyComparer();

            return(comparer.Equals(this, obj));
        }