public void Should_UpdatePreferences() { var users = CreateDataContext().AddUsers(5); foreach (var u in users) { var prefRes = GetRepo <UserRepository>() .ForActiveOrg(u.OrgId) .GetPreferences(u.Id); Assert.False(prefRes.HasError); var model = prefRes.Value; var emptyModel = new ModelUserPreferences() { UserId = u.Id, OrgId = u.OrgId }; Assert.True(emptyModel.Equals(prefRes.Value)); TestFactory.Update(model); Assert.False(GetRepo <UserRepository>() .ForActiveOrg(u.OrgId) .UpdatePreferences(model) .HasError); prefRes = GetRepo <UserRepository>() .ForActiveOrg(u.OrgId) .GetPreferences(u.Id); Assert.False(prefRes.HasError); Assert.True(model.Equals(prefRes.Value)); } }
public void Should_DeleteUsersAndPreferences() { var users = CreateDataContext().AddUsers(5); CreateDataContext().AddUserPreferences(); Assert.True(CreateDataContext() .Preferences .ToList() .Count == users.Count); foreach (var u in users) { Assert.False(GetRepo <UserRepository>() .ForActiveOrg(u.OrgId) .Delete(u.Id) .HasError); var prefCount = CreateDataContext() .Preferences .ToList() .Count; var userCount = CreateDataContext() .Users .ToList() .Count; Assert.True(prefCount == userCount); var model = GetRepo <UserRepository>() .ForActiveOrg(u.OrgId) .GetPreferences(u.Id); Assert.False(model.HasError); var emptyModel = new ModelUserPreferences() { UserId = u.Id, OrgId = u.OrgId }; Assert.True(emptyModel.Equals(model.Value)); } Assert.Empty(CreateDataContext() .Preferences .ToList()); }
public void ShouldNot_UpdatePreferencesWhenBadUserId() { var users = CreateDataContext().AddUsers(5); foreach (var u in users) { var prefRes = GetRepo <UserRepository>() .ForActiveOrg(u.OrgId) .GetPreferences(u.Id); Assert.False(prefRes.HasError); var model = prefRes.Value; var emptyModel = new ModelUserPreferences() { UserId = u.Id, OrgId = u.OrgId }; Assert.True(emptyModel.Equals(prefRes.Value)); TestFactory.Update(model); Assert.True(GetRepo <UserRepository>() .ForActiveOrg(0) .UpdatePreferences(model) .Error .Code == ErrorCode.BadUpdateUserPreferences); model.UserId = TestFactory.GetRandomUShort(1000) + 1000; Assert.True(GetRepo <UserRepository>() .ForActiveOrg(u.OrgId) .UpdatePreferences(model) .Error .Code == ErrorCode.BadUpdateUserPreferences); } }