public void Successful() { // data var user = new Core.Data.Model.User { Id = Guid.NewGuid(), UserName = "******", FirstName = "Angel", LastName = "Arce", DisplayName = "A.Arce", Active = true, CreatedDate = DateTime.Now }; // mocks var validator = Mocks.StrictMock <Core.Validation.UserValidator>(); var persistor = Mocks.StrictMock <Core.Data.Persistor.User>(); var bll = Mocks.StrictMock <Core.Logic.UserLogic>(persistor, validator); // record bll.Expect(b => b.Save(user)).CallOriginalMethod(OriginalCallOptions.NoExpectation); validator.Expect(v => v.Validate(user)).Return(new Core.Validation.ValidatorResult(true)); persistor.Expect(u => u.Save(user)).Return(user); persistor.Expect(u => u.Commit()).Return(1); Mocks.ReplayAll(); var result = bll.Save(user); Assert.Equal(user.Id, result.Id); Mocks.VerifyAll(); }
public void Successful() { var userId = Guid.Empty; var user = new Core.Data.Model.User { Id = userId, UserName = "******", FirstName = "Test", LastName = "Tester", DisplayName = "Tester", Email = "*****@*****.**", Active = true, CreatedDate = DateTime.Parse("06/16/2013") }; var persistor = new Core.Data.Persistor.User(); persistor.Save(user); persistor.Commit(); Assert.NotEqual(Guid.Empty, user.Id); const string sqlFormatter = "IF NOT EXISTS (" + "SELECT COUNT(*) FROM Users WHERE Id = '{0}' HAVING COUNT(*) = 1" + ") RAISERROR ('Error creating user.',16,1);"; var sql = string.Format(sqlFormatter, user.Id); persistor.DbContext.Database.ExecuteSqlCommand(sql); }
public void DuplicateEmail() { var persistor = new Core.Data.Persistor.User(); var sql = Utils.User.GetInsertScript(Guid.Parse("{5CEAD906-4825-4357-A60D-F0363B247CA6}"), "tester12", "*****@*****.**"); persistor.DbContext.Database.ExecuteSqlCommand(sql); sql = "IF NOT EXISTS (" + "SELECT COUNT(*) FROM Users WHERE Id = '{5CEAD906-4825-4357-A60D-F0363B247CA6}' " + "HAVING COUNT(*) = 1) RAISERROR ('Error creating user.',16,1); "; persistor.DbContext.Database.ExecuteSqlCommand(sql); var userId = Guid.Empty; var user = new Core.Data.Model.User { Id = userId, UserName = "******", FirstName = "Test", LastName = "Tester", DisplayName = "Tester", Active = true, Email = "*****@*****.**", CreatedDate = DateTime.Now }; persistor.Save(user); Exception ex = Assert.Throws <System.Data.Entity.Infrastructure.DbUpdateException>(() => persistor.Commit()); Assert.NotNull(ex.InnerException.InnerException); Assert.True(ex.InnerException.InnerException.Message.Contains("IX_User_Email")); Assert.True(ex.InnerException.InnerException.Message.Contains("*****@*****.**")); }
public void Successful_NewUser() { var user = new Core.Data.Model.User { UserName = "******", Email = "email", CreatedDate = DateTime.Now }; var result = new Core.Validation.UserValidator().Validate(user); Assert.Equal(result.IsValid, true); Assert.Equal(result.Errors.Count, 0); }
public void FailedOn_EmailIsRequired() { var user = new Core.Data.Model.User { Id = Guid.NewGuid(), UserName = "******", CreatedDate = DateTime.Now }; var result = new Core.Validation.UserValidator().Validate(user); Assert.Equal(result.IsValid, false); Assert.Equal(result.Errors.Count, 1); Assert.Equal(result.Errors[0].PropertyName, "Email"); }
public void FailedOn_IdIsRequired() { var user = new Core.Data.Model.User { UserName = "******", Email = "email" }; var result = new Core.Validation.UserValidator().Validate(user); Assert.Equal(result.IsValid, false); Assert.Equal(result.Errors.Count, 1); Assert.Equal(result.Errors[0].PropertyName, "Id"); }
public void FailedOn_AllRequiredProperties() { var user = new Core.Data.Model.User(); var result = new Core.Validation.UserValidator().Validate(user); Assert.Equal(result.IsValid, false); Assert.Equal(result.Errors.Count, 3); Assert.Equal(result.Errors[0].PropertyName, "Id"); Assert.Equal(result.Errors[1].PropertyName, "UserName"); Assert.Equal(result.Errors[2].PropertyName, "Email"); }
public void FailureOn_ModelValidation() { // data var user = new Core.Data.Model.User { Id = Guid.NewGuid(), UserName = "******", FirstName = "Angel", LastName = "Arce", DisplayName = "A.Arce", Active = true, CreatedDate = DateTime.Now }; var validatorResult = new Core.Validation.ValidatorResult(false) { Errors = { new Core.Validation.ValidatorFailure { Message = "Email is requried", PropertyName = "Email" }, new Core.Validation.ValidatorFailure { Message = "UserName is requried", PropertyName = "UserName" } } }; // mocks var validator = Mocks.StrictMock <Core.Validation.UserValidator>(); var persistor = Mocks.StrictMock <Core.Data.Persistor.User>(); var bll = Mocks.StrictMock <Core.Logic.UserLogic>(persistor, validator); // record bll.Expect(b => b.Save(user)).CallOriginalMethod(OriginalCallOptions.NoExpectation); validator.Expect(v => v.Validate(user)).Return(validatorResult); Mocks.ReplayAll(); var ex = Assert.Throws <ArgumentException>(() => bll.Save(user)); Assert.Equal("One or more properties a required\r\nParameter name: Email, UserName", ex.Message); Assert.Equal("Email, UserName", ex.ParamName); Mocks.VerifyAll(); }
public void Successful() { // data var userId = Guid.NewGuid(); var user = new Core.Data.Model.User { Id = userId }; // mocks var persistor = Mocks.StrictMock <Core.Data.Persistor.User>(); var bll = Mocks.StrictMock <Core.Logic.UserLogic>(persistor, null); bll.Expect(b => b.Get(user.Id)).CallOriginalMethod(OriginalCallOptions.NoExpectation); persistor.Expect(d => d.Get(user.Id)).Return(user); // record Mocks.ReplayAll(); var result = bll.Get(userId); Assert.Equal(userId, result.Id); }
public void SuccessfulWithUserId() { // data var userId = Guid.NewGuid(); var user = new Core.Data.Model.User { Id = userId }; // mocks var persistor = Mocks.StrictMock <Core.Data.Persistor.User>(); var bll = Mocks.StrictMock <Core.Logic.UserLogic>(persistor, null); bll.Expect(b => b.IsUserNameInUse("username", user.Id)) .CallOriginalMethod(OriginalCallOptions.NoExpectation); persistor.Expect(d => d.IsUserNameInUse("username", user.Id)).Return(true); // record Mocks.ReplayAll(); var result = bll.IsUserNameInUse("username", user.Id); Assert.True(result); }