public void Update_ShouldCommitUnitOfWork() { var stored = new IncomingUser { UserId = Guid.NewGuid(), DisplayName = "Joe Bloggs" }; _unitOfWork.Setup(u => u.Users.Get(stored.UserId)) .Returns(() => Task.FromResult <IUser>(stored)); _unitOfWork.Setup(u => u.Commit()).Returns(() => Task.CompletedTask); var update = new User { UserId = stored.UserId, DisplayName = "Joey" }; Silo.CreateGrain <UserGrain>(stored.UserId) .Update(update).GetAwaiter().GetResult(); stored.DisplayName.Should().Be(update.DisplayName); _unitOfWork.Verify(u => u.Commit(), Times.Once(), "because we need to commit our changes"); }
public void Add(IncomingUser user) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { uow.IncomingUserRepository.AddOrUpdate(user); uow.Save(); } }
public bool Exists(IncomingUser user) { using (var context = new WorldOfWordsDatabaseContext()) { return(context.Users.Any(users => users.Email.ToLower() == user.Email.ToLower()) || context.IncomingUsers.Any(users => users.Email.ToLower() == user.Email.ToLower())); } }
public void Add(IncomingUser user) { using (var context = new WorldOfWordsDatabaseContext()) { context.IncomingUsers.AddOrUpdate(user); context.SaveChanges(); } }
public bool Exists(IncomingUser user) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { return (uow.UserRepository.GetAll().Any(users => users.Email.ToLower() == user.Email.ToLower()) || uow.IncomingUserRepository.GetAll().Any(users => users.Email.ToLower() == user.Email.ToLower())); } }
public User ToDomainModel(IncomingUser incomingUser) { return(new User { Id = incomingUser.Id, Name = incomingUser.Name, Email = incomingUser.Email, Password = incomingUser.Password }); }
public void AddToken(IncomingUser user) { if (Exists(user)) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var searchedUser = uow.IncomingUserRepository.GetById(user.Id); searchedUser.Token = user.Token; uow.Save(); } } }
public void ToDataModel_ShouldTransferAllFields() { var original = new User(); var expected = new IncomingUser(); original.UserId = expected.UserId = Guid.NewGuid(); original.DisplayName = expected.DisplayName = "Joe Bloggs"; original.EmailAddress = expected.EmailAddress = "*****@*****.**"; original.ToDataModel().Should().BeEquivalentTo(expected, "because we expect all fields to be transferred"); }
public void AddToken(IncomingUser user) { if (Exists(user)) { using (var context = new WorldOfWordsDatabaseContext()) { var searchedUser = context.IncomingUsers.First(e => e.Id == user.Id); searchedUser.Token = user.Token; context.SaveChanges(); } } }
public void Add(IncomingUser user) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { uow.IncomingUserRepository.AddOrUpdate(user); uow.Save(); } //using (var context = new WorldOfWordsDatabaseContext()) //{ // context.IncomingUsers.AddOrUpdate(user); // context.SaveChanges(); //} }
public bool Exists(IncomingUser user) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { return(uow.UserRepository.GetAll().Any(users => users.Email.ToLower() == user.Email.ToLower()) || uow.IncomingUserRepository.GetAll().Any(users => users.Email.ToLower() == user.Email.ToLower())); } //using (var context = new WorldOfWordsDatabaseContext()) //{ // return context.Users.Any(users => users.Email.ToLower() == user.Email.ToLower()) // || context.IncomingUsers.Any(users => users.Email.ToLower() == user.Email.ToLower()); //} }
public void AddToken(IncomingUser user) { if (Exists(user)) { using (var uow = _unitOfWorkFactory.GetUnitOfWork()) { var searchedUser = uow.IncomingUserRepository.GetById(user.Id); searchedUser.Token = user.Token; uow.Save(); } //using (var context = new WorldOfWordsDatabaseContext()) //{ // var searchedUser = context.IncomingUsers.First(e => e.Id == user.Id); // searchedUser.Token = user.Token; // context.SaveChanges(); //} } }
public void Find_ShouldReturnGrainModel() { var stored = new IncomingUser { UserId = Guid.NewGuid() }; _unitOfWork.Setup(u => u.Users.Get(stored.UserId)) .Returns(() => Task.FromResult <IUser>(stored)); var grain = Silo.CreateGrain <UserGrain>(stored.UserId); grain.Find().GetAwaiter().GetResult().Should().BeEquivalentTo(stored.ToGrainModel(), "becuase that's what the UnitOfWork provided"); _unitOfWork.Verify(u => u.Users.Get(stored.UserId), Times.Once(), "because we need to call it just once"); _unitOfWork.VerifyNoOtherCalls(); }
public void Setup() { uowFactory = new Mock <IUnitOfWorkFactory>(); worldOfWordsUow = new Mock <IWorldOfWordsUow>(); incUserReposit = new Mock <IIncomingUserRepository>(); tokenVaidation = new Mock <ITokenValidation>(); userReposit = new Mock <IUserRepository>(); iusService = new Mock <IUserService>(); incUserMapper = new Mock <IIncomingUserMapper>(); userForListMaper = new Mock <IUserForListingMapper>(); uowFactory.Setup(t => t.GetUnitOfWork()).Returns(worldOfWordsUow.Object); usServ = new UserService(incUserMapper.Object, tokenVaidation.Object, uowFactory.Object, userForListMaper.Object); roleRepository = new Mock <IRepository <Role> >(); entity = new IncomingUser { Email = "*****@*****.**", Id = 1, Password = "******", Name = "Roman", Token = "jsdjsjd" }; }
public async Task Post_Register_Should_Return_Ok_TokenModel() { //Arrange var registerUser = new RegisterUserModel { Login = "******", Email = "*****@*****.**", Password = "******", Id = 0 }; var incomingUser = new IncomingUser { Name = "Cat-Ok", Email = "*****@*****.**", Password = "******", Token = "asdf", Id = 1 }; var user = new User { Name = "Roman Hapatyn", Email = "*****@*****.**", Password = "******", HashedToken = "asdf", Id = 1 }; TokenModel token = new TokenModel(); token.RolesToken = "Student"; //Action GenerateData("1", new[] { "NoRoles" }); RegisterController registerController = new RegisterController(userService.Object, tokenValidation.Object, incUserMapper.Object, mesService.Object); var tokenModel = new TokenModel(); string locationUrl = "http://location/"; var message = new IdentityMessage { Body = "Please confirm your account at: www.xxx.xxx ", Destination = "*****@*****.**", Subject = "Confirm your registration" }; urlHelper.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())) .Returns(locationUrl); registerController.Url = urlHelper.Object; mesService .Setup(x => x.SendAsync(message)) .Returns(Task.FromResult(0)); incUserMapper .Setup(x => x.ToIncomingUser(registerUser)) .Returns(incomingUser); userMapper .Setup(x => x.Map(registerUser)) .Returns(user); userService .Setup(x => x.Exists(incomingUser)) .Returns(false); tokenValidation .Setup(x => x.GetHashSha256("asdf")) .Returns("fdsa"); var actual = await registerController.Post(registerUser) as OkNegotiatedContentResult <TokenModel>; var contentResult = actual as OkNegotiatedContentResult <TokenModel>; //Assert Assert.IsNotNull(actual); Assert.AreEqual(actual.Content.GetType(), tokenModel.GetType()); }
[Test] // public void ConfirmUserRegistration_IsFalseTest() { //Arrange IncomingUser inUser = new IncomingUser { Email = "*****@*****.**", Id = 1, Password = "******", Name = "Stepan", Token = "jsdjsjd" }; IQueryable <IncomingUser> incomUsers = new List <IncomingUser> { inUser }.AsQueryable <IncomingUser>(); User user = new User { Email = "*****@*****.**", Id = 1, Password = "******", Name = "Stepan", HashedToken = "sknsdmsopp" }; IQueryable <Role> roles = new List <Role> { new Role() { Id = 1, Name = "Student" } }.AsQueryable <Role>(); worldOfWordsUow.Setup(t => t.IncomingUserRepository).Returns(incUserReposit.Object); incUserReposit.Setup(t => t.GetAll()).Returns(incomUsers); incUserReposit.Setup(s => s.Delete(It.IsAny <IncomingUser>())).Verifiable("deleted"); incUserMapper.Setup(t => t.ToDomainModel(It.IsAny <IncomingUser>())).Returns(user); worldOfWordsUow.Setup(t => t.RoleRepository).Returns(roleRepository.Object); roleRepository.Setup(t => t.GetAll()).Returns(roles); worldOfWordsUow.Setup(t => t.UserRepository).Returns(userReposit.Object); userReposit.Setup(t => t.Add(user)).Verifiable("Added user"); worldOfWordsUow.Setup(t => t.Save()).Verifiable("Saved"); //Act var result = usServ.ConfirmUserRegistration(2, "jaflkasjdl"); //Assert uowFactory.Verify(t => t.GetUnitOfWork(), Times.Once); worldOfWordsUow.Verify(t => t.IncomingUserRepository, Times.Once); incUserReposit.Verify(t => t.GetAll(), Times.Once); incUserReposit.Verify(t => t.Delete(It.IsAny <IncomingUser>()), Times.Never); incUserMapper.Verify(t => t.ToDomainModel(It.IsAny <IncomingUser>()), Times.Never); worldOfWordsUow.Verify(t => t.RoleRepository, Times.Never); roleRepository.Verify(t => t.GetAll(), Times.Never); worldOfWordsUow.Verify(t => t.UserRepository, Times.Never); userReposit.Verify(t => t.Add(It.IsAny <User>()), Times.Never); worldOfWordsUow.Verify(t => t.Save(), Times.Never); Assert.IsFalse(result); }