public void Call_SaveChangesMethodOfTheUnitOfWork()
        {
            // Arrange
            var characters = new List <User>()
            {
                new User()
                {
                    UserName            = "******",
                    FavoritesCharacters = new HashSet <CharacterDataModel>()
                }
            };
            var characterData = new CharacterDataModel();

            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedRepo       = new Mock <IEfRepository <User> >();

            mockedUnitOfWork.Setup(unit => unit.SaveChanges());
            mockedRepo.Setup(repo => repo.All).Returns(characters);

            var userService = new UserService(mockedUnitOfWork.Object, mockedRepo.Object);

            // Act
            userService.AddToFavoritesCharacters("username", characterData);

            // Assert
            mockedUnitOfWork.Verify(unit => unit.SaveChanges(), Times.Once);
        }
Beispiel #2
0
        public void Call_SaveChangesMethod_OfTheUnitOfWork()
        {
            // Arrange
            var charactersDataModels = new List <CharacterDataModel>()
            {
                new CharacterDataModel()
                {
                    Id = 1
                }
            };

            var characterDataObject = new CharacterDataModel()
            {
                Id          = 1,
                Image       = "asdasda",
                Description = "asdasdsa",
                isDeleted   = false,
                Name        = "adasd"
            };

            var mockedUnitOfwork = new Mock <IUnitOfWork>();
            var mockedRepo       = new Mock <IEfRepository <CharacterDataModel> >();

            mockedRepo.Setup(repo => repo.All).Returns(charactersDataModels);
            mockedUnitOfwork.Setup(unit => unit.SaveChanges());

            var characterService = new CharacterService(mockedUnitOfwork.Object, mockedRepo.Object);


            // Act
            characterService.EditCharacter(characterDataObject);

            // Assert
            mockedUnitOfwork.Verify(unit => unit.SaveChanges(), Times.Once);
        }
Beispiel #3
0
        public void Call_AllProperty_OfTheRepository()
        {
            // Arrange
            var charactersDataModel = new List <CharacterDataModel>()
            {
                new CharacterDataModel()
                {
                    Id        = 1,
                    isDeleted = false,
                    Name      = "Mitko"
                }
            };

            var characterModel = new CharacterDataModel()
            {
                Id          = 1,
                Image       = "asdasd",
                Description = "asdasds",
                Name        = "Mitko"
            };

            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedRepo       = new Mock <IEfRepository <CharacterDataModel> >();

            mockedRepo.Setup(repo => repo.All).Returns(charactersDataModel);
            mockedUnitOfWork.Setup(unit => unit.SaveChanges());

            var characterService = new CharacterService(mockedUnitOfWork.Object, mockedRepo.Object);

            // Act
            characterService.RemoveCharacter(characterModel);

            // Assert
            mockedRepo.Verify(repo => repo.All, Times.Once);
        }
Beispiel #4
0
        public void AddCharacter(CharacterDataModel character)
        {
            Guard.WhenArgument(character, nameof(character)).IsNull().Throw();

            this.characters.Add(character);

            this.unitOfwork.SaveChanges();
        }
Beispiel #5
0
        public void RemoveCharacter(CharacterDataModel character)
        {
            Guard.WhenArgument(character, nameof(character)).IsNull().Throw();

            var characterToRemove = this.characters.All.First(c => c.isDeleted != true && c.Name == character.Name);

            characterToRemove.isDeleted = true;

            this.unitOfwork.SaveChanges();
        }
        public void AddToFavoritesCharacters(string username, CharacterDataModel characterModel)
        {
            Guard.WhenArgument(username, nameof(username)).IsNull().Throw();
            Guard.WhenArgument(characterModel, nameof(characterModel)).IsNull().Throw();

            var user = this.usersRepository.All.FirstOrDefault(usr => usr.UserName == username);

            user.FavoritesCharacters.Add(characterModel);

            this.unitOfWork.SaveChanges();
        }
Beispiel #7
0
 public bool Create(CharacterDataModel character)
 {
     try
     {
         _context.Add(character);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
        public void ThrowArgumentNullException_WheIsPassed_InvalidUsername()
        {
            // Arrange
            var characterDataModel = new CharacterDataModel();

            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var mockedRepo       = new Mock <IEfRepository <User> >();

            var userService = new UserService(mockedUnitOfWork.Object, mockedRepo.Object);

            // Act & Assert
            Assert.That(() => userService.AddToFavoritesCharacters(null, characterDataModel),
                        Throws.ArgumentNullException.With.Message.Contain("username"));
        }
Beispiel #9
0
        public void Return_ErrorViewResult()
        {
            // Arrange
            CharacterDataModel invalidCharacterModel = null;

            var mockedService = new Mock <ICharacterService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedService.Setup(service => service.GetCharacter("name")).Returns(invalidCharacterModel);

            var characterAdministrationController = new CharactersAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            //var result = characterAdministrationController.GetCharacterByName("name") as ViewResult;

            // Assert
            //Assert.AreEqual("NotFound", result.ViewName);
        }
Beispiel #10
0
        public async Task <IActionResult> ViewCharacter(string characterName, string characterRealm)
        {
            string cName  = characterName.ToLower();
            string cRealm = characterRealm.ToLower();

            ApiHelper.InitialiseClient();
            CharacterModel character = await CharacterProcessor.LoadCharacter(cName, cRealm);

            CharacterStatsModel characterStats = await CharacterProcessor.LoadCharacterStats(cName, cRealm);

            CharacterDataModel characterData = new CharacterDataModel();

            characterData.CharacterData      = character;
            characterData.CharacterStatsData = characterStats;



            return(View(characterData));
        }
Beispiel #11
0
        public void Call_AddMethod_OfTheDbSet()
        {
            // Arrange
            var characterDataModel = new CharacterDataModel();

            var mockedDbSet     = new Mock <IDbSet <CharacterDataModel> >();
            var mockedDbContext = new Mock <IEfMarvelCatalogDbContext>();

            mockedDbContext.Setup(db => db.GetSet <CharacterDataModel>()).Returns(mockedDbSet.Object);
            mockedDbSet.Setup(set => set.Add(characterDataModel));

            var repo = new EfRepository <CharacterDataModel>(mockedDbContext.Object);

            // Act
            repo.Add(characterDataModel);

            // Assert
            mockedDbSet.Verify(set => set.Add(characterDataModel), Times.Once);
        }
Beispiel #12
0
        public void Call_GetCharacterMethod_FromTheService()
        {
            // Arrange
            var characterDataModel = new CharacterDataModel();

            var mockedService = new Mock <ICharacterService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedService.Setup(service => service.GetCharacter("name")).Returns(characterDataModel);

            var characterAdministrationController = new CharactersAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            characterAdministrationController.GetCharacterByName("name");

            // Assert
            mockedService.Verify(service => service.GetCharacter("name"), Times.Once);
        }
Beispiel #13
0
        public void Call_SaveChangesMethod_OfTheEfUnitOfWork()
        {
            // Arrange
            var characterDataModel = new CharacterDataModel();

            var mockedUnitOfwork = new Mock <IUnitOfWork>();
            var mockedRepo       = new Mock <IEfRepository <CharacterDataModel> >();

            mockedUnitOfwork.Setup(unit => unit.SaveChanges()).Returns(1);
            mockedRepo.Setup(repo => repo.Add(characterDataModel));

            var characterService = new CharacterService(mockedUnitOfwork.Object, mockedRepo.Object);

            // Act
            characterService.AddCharacter(characterDataModel);

            // Assert
            mockedUnitOfwork.Verify(unit => unit.SaveChanges(), Times.Once);
        }
Beispiel #14
0
        public void Call_CreateCharacterMethod_FromTheFactory()
        {
            // Arrange
            var characterDataModel = new CharacterDataModel();
            var characterViewModel = new CharacterViewModel();

            var mockedService = new Mock <ICharacterService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedFactory.Setup(fac => fac.CreateCharacter()).Returns(characterDataModel);
            mockedService.Setup(service => service.AddCharacter(characterDataModel));

            var characterAdminController = new CharactersAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            characterAdminController.AddCharacterToDb(characterViewModel);

            // Assert
            mockedFactory.Verify(fac => fac.CreateCharacter(), Times.Once);
        }
Beispiel #15
0
        public void Call_MapMethod_FromMapper()
        {
            // Arrange
            var characterName = "some name";

            var characterDataModel = new CharacterDataModel();
            var characterViewModel = new CharacterViewModel("", "", "", "asda", "asdasd", "asdasda");

            var mockedService = new Mock <ICharacterService>();
            var mockedMapper  = new Mock <IMapper>();

            mockedService.Setup(service => service.GetCharacter(characterName)).Returns(characterDataModel);
            mockedMapper.Setup(mapper => mapper.Map <CharacterViewModel>(characterDataModel)).Returns(characterViewModel);

            var characterController = new CharactersController(mockedService.Object, mockedMapper.Object);

            // Act
            characterController.GivenCharacterPage(characterName);

            // Assert
            mockedMapper.Verify(mapper => mapper.Map <CharacterViewModel>(characterDataModel), Times.Once);
        }
        public void Call_MapMethod_FromTheMapper()
        {
            // Arrange
            var characterDataModel = new CharacterDataModel();
            var characterVeiwModel = new CharactersAdminViewModel();

            var mockedService = new Mock <ICharacterService>();
            var mockedMapper  = new Mock <IMapper>();
            var mockedFactory = new Mock <IDataModelsFactory>();

            mockedService.Setup(service => service.GetCharacterById(1))
            .Returns(characterDataModel);
            mockedMapper.Setup(mapper => mapper.Map <CharactersAdminViewModel>(characterVeiwModel))
            .Returns(characterVeiwModel);

            var characterAdminController = new CharactersAdministrationController(mockedService.Object, mockedMapper.Object, mockedFactory.Object);

            // Act
            characterAdminController.GetCharacterById(1);

            // Arrange
            mockedMapper.Verify(mapper => mapper.Map <CharactersAdminViewModel>(characterDataModel), Times.Once);
        }
Beispiel #17
0
        public bool Create(CharacterCreateRequest request)
        {
            CharacterDataModel character = _converter.RequestToDataModel(request);

            return(_repository.Create(character));
        }