Ejemplo n.º 1
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="userConfirmation"></param>
        /// <returns></returns>
        public UserConfirmationDto Update(UserConfirmationDto userConfirmation)
        {
            UserConfirmation user = userConfirmation.ExposedAs<UserConfirmation>(Repository);
            Repository.Update<UserConfirmation>(user);

            UnitOfWork.Save();

            return userConfirmation;
        }
Ejemplo n.º 2
0
        public void Update_AnyId_CallsUpdateMethodOfRepository()
        {
            var settingsMock = new Mock<ISettings>();
            var componentsMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            Guid id = Guid.NewGuid();
            string token = Guid.NewGuid().ToString();
            UserConfirmationDto userConfirmationDto = new UserConfirmationDto
            {
                Id = id
            };
            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);
            // Act
            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
            userService.Update(userConfirmationDto);

            // Assert
            repositoryMock.Verify(repo => repo.Update<UserConfirmation>(
                It.Is<UserConfirmation>(u => u.Id == id)));
            uowMock.Verify(uow => uow.Save());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create
        /// </summary>
        /// <param name="userConfirmation"></param>
        /// <returns></returns>
        public UserConfirmationDto Create(UserConfirmationDto userConfirmDto)
        {
            UserConfirmation userConfirm = userConfirmDto.ExposedAs<UserConfirmation>(Repository);

            userConfirm.User = Repository.FindById<User>(userConfirmDto.User.Id);

            Repository.Insert<UserConfirmation>(userConfirm);

            UnitOfWork.Save();

            return userConfirm.ExposedAs<UserConfirmationDto>();
        }
Ejemplo n.º 4
0
        public void CreateUserConfirmationDto_Any_CallsCreateMethodOfRepository()
        {
            var settingsMock = new Mock<ISettings>();
            var componentsMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            Guid id = Guid.NewGuid();
            UserDto user = new UserDto()
            {
                Id = Guid.NewGuid()
            };
            UserConfirmationDto userConfirmationDto = new UserConfirmationDto
            {
                Id = id,
                Type= ConfirmedType.ChangeEmail,
              User=user
            };

             repositoryMock.Setup(r => r.FindById<User>(user.Id));
            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);
            // Act
            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
              UserConfirmationDto actualUser=  userService.Create(userConfirmationDto);

            // Assert
            repositoryMock.Verify(repo => repo.Insert<UserConfirmation>(
                It.Is<UserConfirmation>(u => u.Id == id)));
            uowMock.Verify(uow => uow.Save());
            Assert.AreEqual(actualUser.Id, id);
        }