コード例 #1
0
        /// <summary>
        /// Create a user at reigistration overall step
        /// </summary>
        /// <param name="user"></param>
        public RegistrationOverallDto Create(RegistrationOverallDto user)
        {
            var userEntity = user.ExposedAs<User>(Repository);
            userEntity.AvailabilityStatus = AvailabilityStatus.Available;
            Repository.Insert<User>(userEntity);

            UnitOfWork.Save();

            return userEntity.ExposedAs<RegistrationOverallDto>();
        }
コード例 #2
0
        public void CreateUser_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();
            RegistrationOverallDto user = new RegistrationOverallDto
            {
                Id = id,
                UserName = "******",
                Email = "*****@*****.**",
                MobilePhone="0978069219"
            };

            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);
            // Act
            var userService = new UserService(uowMock.Object,repositoryMock.Object, settingsMock.Object, componentsMock.Object);
            userService.Create(user);

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