public SearchFixture() { var userId = Guid.NewGuid(); _userId = Guid.NewGuid(); _badClientId = Guid.NewGuid(); _clients = new Dictionary <Guid, string> { { Guid.Parse("{14D83039-606E-4B67-8A43-62743A3A6BEC}"), "A" }, { Guid.Parse("{006D3BA4-81A2-4FDB-96F9-4E86351454D1}"), "B" }, { Guid.Parse("{FB642139-0640-4359-B94E-A5A948E78E89}"), "C" }, { Guid.Parse("{7D0CF51F-3386-47B8-8CBF-51173CD5AA0D}"), "D" } }; var repo = new Core.Data.Persistor.Client(); repo.DbContext.Database.ExecuteSqlCommand( Utils.User.GetInsertScript(_userId, "test-username", "*****@*****.**")); repo.DbContext.Database.ExecuteSqlCommand( Utils.User.GetInsertScript(userId, "test-username2", "*****@*****.**")); repo.DbContext.Database.ExecuteSqlCommand( Utils.Client.GetInsertScript(_badClientId, userId, "non-retrieved-company")); foreach (var client in _clients) { repo.DbContext.Database.ExecuteSqlCommand( Utils.Client.GetInsertScript(client.Key, _userId, client.Value)); } }
public void Successful() { var persistor = new Core.Data.Persistor.Client(); var userId = Guid.Parse("{5CEAD906-4825-4357-A60D-F0363B247CA6}"); var sql = Utils.User.GetInsertScript(userId, "user 1", "*****@*****.**"); persistor.DbContext.Database.ExecuteSqlCommand(sql); var clientId = Guid.Empty; var client = new Core.Data.Model.Client { Id = clientId, Active = true, CompanyName = "Client name", CreatedDate = DateTime.Now, User_Id = userId, }; persistor.Save(client); persistor.Commit(); const string sqlFormatter = "IF NOT EXISTS (" + "SELECT COUNT(*) FROM Clients WHERE Id = '{0}' AND CompanyName = '{1}' AND User_Id = '{2}' " + "HAVING COUNT(*) = 1" + ") RAISERROR ('Error creating client.',16,1);"; Assert.NotEqual(clientId, client.Id); sql = string.Format(sqlFormatter, client.Id, "Client name", userId); persistor.DbContext.Database.ExecuteSqlCommand(sql); }
public void WithContacts() { var repo = new Core.Data.Persistor.Client(); repo.DbContext.Database.ExecuteSqlCommand( Utils.ClientContact.GetInsertScript(Guid.NewGuid(), _clientId)); VerifyDelete(); }
public void ByPageAndPageSize() { var repo = new Core.Data.Persistor.Client(); var coll = repo.Search(new Core.Data.Search.ClientCriteria { UserId = _userId, Page = 1, PageSize = 2 }).ToList(); Assert.Equal(2, coll.Count()); Assert.Null(coll.FirstOrDefault(c => c.Id == _badClientId)); }
public void ByUserAndCompanyName() { var repo = new Core.Data.Persistor.Client(); var coll = repo.Search(new Core.Data.Search.ClientCriteria { UserId = _userId, CompanyName = "Company_C" }).ToList(); Assert.Equal(1, coll.Count()); Assert.NotNull(coll.FirstOrDefault(r => r.Id == Guid.Parse("FB642139-0640-4359-B94E-A5A948E78E89"))); }
public DeleteFixture() { _clientId = Guid.NewGuid(); var repo = new Core.Data.Persistor.Client(); repo.DbContext.Database.ExecuteSqlCommand( Utils.User.GetInsertScript(_userId, "test-username", "*****@*****.**")); repo.DbContext.Database.ExecuteSqlCommand( Utils.Client.GetInsertScript(_clientId, _userId, "client-company")); }
public void ByUser() { var repo = new Core.Data.Persistor.Client(); var coll = repo.Search(new Core.Data.Search.ClientCriteria { UserId = _userId }).ToList(); Assert.Equal(4, coll.Count()); foreach (var clientId in _clients.Select(client => client.Key)) { var id = clientId; Assert.NotNull(coll.FirstOrDefault(r => r.Id == id)); } }
public void WithInvoice() { var invoiceId = Guid.NewGuid(); var repo = new Core.Data.Persistor.Client(); // insert invoice repo.DbContext.Database.ExecuteSqlCommand( Utils.Invoice.GetInsertScript(invoiceId, _clientId, DateTime.Now, _userId)); // insert invoice item repo.DbContext.Database.ExecuteSqlCommand( Utils.InvoiceItem.GetInsertScript(Guid.NewGuid(), invoiceId, 2, 320000)); VerifyDelete(); }
private void VerifyDelete() { var repo = new Core.Data.Persistor.Client(); var sql = string.Format("IF NOT EXISTS (" + "SELECT COUNT(*) FROM Clients WHERE Id = '{0}' HAVING COUNT(*) > 0" + ") RAISERROR ('Client not found.',16,1);", _clientId); repo.DbContext.Database.ExecuteSqlCommand(sql); repo.Delete(_clientId); repo.Commit(); sql = string.Format("IF EXISTS (" + "SELECT COUNT(*) FROM Clients WHERE Id = '{0}' HAVING COUNT(*) > 0" + ") RAISERROR ('Error deleting client.',16,1);", _clientId); repo.DbContext.Database.ExecuteSqlCommand(sql); }