public void TestInvoices() { var departmentA = new DepartmentBuilder(this.Session).Build(); var departmentB = new DepartmentBuilder(this.Session).Build(); var accountantA = new PersonBuilder(this.Session).WithFirstName("Accountant").WithLastName("A").Build(); var accountantB = new PersonBuilder(this.Session).WithFirstName("Accountant").WithLastName("B").Build(); departmentA.AddAccountant(accountantA); departmentB.AddAccountant(accountantB); var invoiceA = new InvoiceBuilder(this.Session).Build(); var invoiceB = new InvoiceBuilder(this.Session).Build(); departmentA.AddInvoice(invoiceA); departmentB.AddInvoice(invoiceB); this.Session.Derive(); // Accountant A var aclAccountatAInvoiceA = new AccessControlList(invoiceA, accountantA); var aclAccountatAInvoiceB = new AccessControlList(invoiceB, accountantA); aclAccountatAInvoiceA.CanWrite(Invoice.Meta.Total).ShouldBeTrue(); aclAccountatAInvoiceB.CanWrite(Invoice.Meta.Total).ShouldBeFalse(); // Accountant B var aclAccountatBInvoiceA = new AccessControlList(invoiceA, accountantB); var aclAccountatBInvoiceB = new AccessControlList(invoiceB, accountantB); aclAccountatBInvoiceA.CanWrite(Invoice.Meta.Total).ShouldBeFalse(); aclAccountatBInvoiceB.CanWrite(Invoice.Meta.Total).ShouldBeTrue(); }
public void ShouldSaveAndFetchDepartment() { var department = new DepartmentBuilder().Build(); this.departmentRepository.SaveOrUpdate(department); this.FlushAndClearSession(); var departmentRetrieved = this.departmentRepository.GetById(department.Id); Assert.IsNotNull(departmentRetrieved); Assert.That(departmentRetrieved.Id, Is.Not.EqualTo(0)); }
public void ShouldGetDepartmentByCode() { const string DepartmentCode = "DD1"; var department = new DepartmentBuilder().WithDepartmentCode(DepartmentCode).Build(); departmentRepository.SaveOrUpdate(department); FlushAndClearSession(); var departmentRetrieved = departmentRepository.GetByCode(DepartmentCode); Assert.IsNotNull(departmentRetrieved); Assert.That(department.Id, Is.EqualTo(departmentRetrieved.Id)); }
public void ShouldCheckUniqueConstaintOfRollNumber() { var department1 = new DepartmentBuilder().WithDepartmentCode("DD1").Build(); departmentRepository.SaveOrUpdate(department1); FlushAndClearSession(); var department2 = new DepartmentBuilder().WithDepartmentCode("DD1").Build(); var exception = Assert.Catch(() => this.departmentRepository.SaveOrUpdate(department2)); Assert.That(exception.InnerException.GetType(), Is.EqualTo(typeof(SqlException))); Assert.That(exception.InnerException.Message.Contains("Violation of UNIQUE KEY constraint")); }
public void JustLine100000WithTasks() { int n = 100000; var departmentBuilder = new DepartmentBuilder(n, n); var organizationConfig = new OrganizationConfig() { StartDepartment = 1, EndDepartment = n, NumberOfDepartments = n, NumberOfStamps = n, }; for (int i = 0; i < n; i++) { int j = (i + 1) % n; organizationConfig.Departments.Add ( departmentBuilder.GetDepartment(i + 1, j + 1, j + 1) ); } var organization = new Organization(organizationConfig); List <Task> tasks = new List <Task>(); for (int i = 1; i <= n / 100; i++) { var i1 = i; tasks.Add(new Task(() => { var a = organization.GetResult(i1); Assert.IsNotNull(a); Assert.IsNotNull(a.Checklists); Assert.IsTrue(a.Checklists.Count == 1); var uncheckedStamps = a.Checklists[0].GetAllUncheckedStamps(); if (i1 == n) { Assert.IsTrue(uncheckedStamps.Count == 1 && uncheckedStamps[0] == 1); } else { foreach (var stamp in uncheckedStamps) { Assert.IsTrue(stamp > i1); } } Assert.IsTrue(a.Status == DepartmentStatus.Visited); })); tasks[i - 1].Start(); } Task.WaitAll(tasks.ToArray()); }
public void SimpleCycle() { var departmentBuilder = new DepartmentBuilder(6, 5); var organizationConfig = new OrganizationConfig() { StartDepartment = 1, EndDepartment = 6, NumberOfDepartments = 6, NumberOfStamps = 5, }; for (int i = 0; i < 4; i++) { int j = (i + 1) % 5; organizationConfig.Departments.Add ( departmentBuilder.GetDepartment(i + 1, j + 1, j + 1) ); } organizationConfig.Departments.Add ( departmentBuilder.GetDepartment(5, 5, 1, 1, 5, 1, 6) ); organizationConfig.Departments.Add(departmentBuilder.GetDepartment(1, 2, 1)); var organization = new Organization(organizationConfig); for (int i = 1; i <= 6; i++) { var a = organization.GetResult(i); Assert.IsNotNull(a); Assert.IsNotNull(a.Checklists); foreach (var aChecklist in a.Checklists) { var ch = a.Checklists[0].GetAllUncheckedStamps(); if (a.Status == DepartmentStatus.InCycle) { Assert.IsNotNull(ch); Assert.IsTrue(a.Checklists.Count == 2 || i == 4 || i == 5); } } Assert.IsTrue(a.Status == DepartmentStatus.InCycle || a.Status == DepartmentStatus.Inaccessible); } }
public void JustLine10000() { int n = 10000; var departmentBuilder = new DepartmentBuilder(n, n); var organizationConfig = new OrganizationConfig() { StartDepartment = 1, EndDepartment = n, NumberOfDepartments = n, NumberOfStamps = n, }; for (int i = 0; i < n; i++) { int j = (i + 1) % n; organizationConfig.Departments.Add ( departmentBuilder.GetDepartment(i + 1, j + 1, j + 1) ); } var organization = new Organization(organizationConfig); for (int i = 1; i <= n; i++) { var a = organization.GetResult(i); Assert.IsNotNull(a); Assert.IsNotNull(a.Checklists); Assert.IsTrue(a.Checklists.Count == 1); var uncheckedStamps = a.Checklists[0].GetAllUncheckedStamps(); if (i == n) { Assert.IsTrue(uncheckedStamps.Count == 1 && uncheckedStamps[0] == 1); } else { foreach (var stamp in uncheckedStamps) { Assert.IsTrue(stamp > i); } } Assert.IsTrue(a.Status == DepartmentStatus.Visited); } }
public void ShouldSaveAndFetchStudentWithDepartment() { var department = new DepartmentBuilder().Build(); var departmentRepository = new DepartmentRepository(); departmentRepository.SaveOrUpdate(department); var student = new StudentBuilder().Build(); student.Department = department; studentRepository.SaveOrUpdate(student); FlushAndClearSession(); var studentRetrieved = studentRepository.GetById(student.Id); Assert.IsNotNull(studentRetrieved); Assert.That(studentRetrieved.Id, Is.Not.EqualTo(0)); Assert.That(studentRetrieved.Department, Is.Not.Null); Assert.That(studentRetrieved.Department.Code, Is.EqualTo(department.Code)); }
public void TaskRequests() { var depBuilder = new DepartmentBuilder(9, 3); var orgConfig = new OrganizationConfig() { StartDepartment = 1, EndDepartment = 9, NumberOfDepartments = 9, NumberOfStamps = 5, }; orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 2)); orgConfig.Departments.Add(depBuilder.GetDepartment(2, 1, 2, 3, 3, 2, 6)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 4)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 5)); orgConfig.Departments.Add(depBuilder.GetDepartment(2, 1, 2)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 7)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 8)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 2)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 1)); var organization = new Organization(orgConfig); var result = organization.GetResult(1); Assert.IsTrue(result.Status == DepartmentStatus.Visited); result = organization.GetResult(9); Assert.IsTrue(result.Status == DepartmentStatus.Inaccessible); List <Task <DepartmentResult> > tasks = new List <Task <DepartmentResult> >(); for (int i = 2; i <= 8; i++) { tasks.Add(new Task <DepartmentResult>(() => organization.GetResult(i))); tasks[i - 2].Start(); } Task.WaitAll(tasks.ToArray()); foreach (var task in tasks) { Assert.IsTrue(task.Result.Status == DepartmentStatus.Inaccessible); } }
public void Cycle8() { var depBuilder = new DepartmentBuilder(9, 3); var orgConfig = new OrganizationConfig() { StartDepartment = 1, EndDepartment = 9, NumberOfDepartments = 9, NumberOfStamps = 5, }; orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 2)); orgConfig.Departments.Add(depBuilder.GetDepartment(2, 1, 2, 3, 3, 2, 6)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 4)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 5)); orgConfig.Departments.Add(depBuilder.GetDepartment(2, 1, 2)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 7)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 8)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 2)); orgConfig.Departments.Add(depBuilder.GetDepartment(1, 2, 1)); var organization = new Organization(orgConfig); var result = organization.GetResult(1); Assert.IsTrue(result.Status == DepartmentStatus.Visited); result = organization.GetResult(9); Assert.IsTrue(result.Status == DepartmentStatus.Inaccessible); for (int i = 2; i <= 8; i++) { result = organization.GetResult(i); Assert.IsTrue(result.Status == DepartmentStatus.InCycle); } }