public bool AcceptPartnership(WcfCommon.Data.HiringCompany hc, WcfCommon.Data.OutsourcingCompany oc) { Log.Info("AddPartnershipToDB..."); HiringCompanyData.HiringCompany hc_data = new HiringCompanyData.HiringCompany(); HiringCompanyData.OutsourcingCompany oc_data = new HiringCompanyData.OutsourcingCompany(); hc_data = HiringCompanyDB.Instance.GetCompany(hc.IdFromHiringCompanyDB); oc_data = OCompanyDB.Instance.GetOutsourcingCompany(oc.Name); return(PartnershipDB.Instance.AddPartnership(hc_data, oc_data)); }
/// <summary> /// Methods that call ServiceProxy to outsourcing company service /// </summary> public bool SendPartnershipRequest(int outsourcingCompanyId, HiringCompanyData.HiringCompany hiringCompany) { WcfCommon.Data.HiringCompany hc_data = new WcfCommon.Data.HiringCompany(); hc_data.Ceo = hiringCompany.Ceo; hc_data.IdFromHiringCompanyDB = hiringCompany.IDHc; hc_data.Name = hiringCompany.Name; bool ret = false; try { ret = ServiceProxy.Instance.SendOcRequest(outsourcingCompanyId, hc_data); } catch (CommunicationException ce) { ServiceProxy.Instance = null; Log.Error("Connection to Outsourcing company service failed."); } catch (Exception e) { ServiceProxy.Instance = null; Log.Error("Connection to Outsourcing company service failed."); } if (ret) { Log.Info("SUCCESSFULLY SENT PARTNERSHIP REQUEST!"); } else { Log.Warn("Failed to sent partnership request."); } return(ret); }
public void SetupTest() { hirignCompanyServiceUnderTest = new HiringCompanyService.HiringCompanyService(); employeeTest = new Employee { Username = "******", Password = "******", Name = "Dusan", Surname = "Jeftic", Position = PositionEnum.CEO.ToString(), StartTime = "9", EndTime = "17", Login = false }; hiringCompanyTest = new HiringCompany { IDHc = 1, Name = "HC-D", Ceo = "Dusan Jeftic", CompanyIdThr = 1 }; projectTest = new Project() { Name = "Project1", StartDate = DateTime.Now, EndDate = DateTime.Now, Description = "Project1 desc" }; ocTest_common = new WcfCommon.Data.OutsourcingCompany() { Name = "OC1", }; ocTestH = new OutsourcingCompany() { Name = "OC1", IdFromOutSourcingDB = 1 }; hcTest_common = new WcfCommon.Data.HiringCompany() { Name = "HC1", IdFromHiringCompanyDB = 1, Ceo = "Dusan Jeftic" }; us = new UserStory() { Name = "US1", Id = 1, Progress = 80, UserStoryState = UserStoryState.Approved, WeightOfUserStory = 3, Description = "Opis", IdFromOcDB = 1 }; #region EmployeeDB EmployeeDB.Instance = Substitute.For <IEmployeeDB>(); EmployeeDB.Instance.AddEmployee(null).ReturnsForAnyArgs(true); EmployeeDB.Instance .WhenForAnyArgs(p => p.AddEmployee(null)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.GetEmployee(null, null).ReturnsForAnyArgs(new Employee()); EmployeeDB.Instance .WhenForAnyArgs(p => p.GetEmployee(null, null)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.ChangeEmployeePosition(usernameTest, null).ReturnsForAnyArgs(true); EmployeeDB.Instance .WhenForAnyArgs(p => p.ChangeEmployeePosition(usernameTest, null)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.GetEmployees().Returns(new List <Employee>()); EmployeeDB.Instance .When(p => p.GetEmployees()) .Do(p => { isCalled = true; }); EmployeeDB.Instance.UpdateEmployee(null).ReturnsForAnyArgs(true); EmployeeDB.Instance .When(p => p.UpdateEmployee(employeeTest)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.ChangeEmployeePassword(usernameTest, passwordTest, newPasswordTest).Returns(true); EmployeeDB.Instance .When(p => p.ChangeEmployeePassword(usernameTest, passwordTest, newPasswordTest)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.EmployeeLogIn(usernameTest).Returns(true); EmployeeDB.Instance .When(p => p.EmployeeLogIn(usernameTest)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.EmployeeLogOut(usernameTest).Returns(true); EmployeeDB.Instance .When(p => p.EmployeeLogOut(usernameTest)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.GetEmployeeEmail(usernameTest).Returns("*****@*****.**"); EmployeeDB.Instance .When(p => p.GetEmployeeEmail(usernameTest)) .Do(p => { isCalled = true; }); EmployeeDB.Instance.GetReallyEmployees().Returns(new List <Employee>()); EmployeeDB.Instance .When(p => p.GetReallyEmployees()) .Do(p => { isCalled = true; }); EmployeeDB.Instance.GetAllNotSignedInEmployees().Returns(new List <Employee>()); EmployeeDB.Instance .When(p => p.GetAllNotSignedInEmployees()) .Do(p => { isCalled = true; }); EmployeeDB.Instance.GetHcIdForUser(employeeTest.Username).Returns(1); EmployeeDB.Instance .WhenForAnyArgs(p => p.GetHcIdForUser(null)) .Do(p => { isCalled = true; }); #endregion EmployeeDB #region HiringCompanyDB HiringCompanyDB.Instance = Substitute.For <IHiringCompanyDB>(); HiringCompanyDB.Instance.AddCompany(null).ReturnsForAnyArgs(true); HiringCompanyDB.Instance .When(p => p.AddCompany(hiringCompanyTest)) .Do(p => { isCalled = true; }); HiringCompanyDB.Instance.GetCompany(1).Returns(hiringCompanyTest); HiringCompanyDB.Instance .When(p => p.GetCompany(1)) .Do(p => { isCalled = true; }); #endregion HiringCompanyDB #region ProjectDB ProjectDB.Instance = Substitute.For <IProjectDB>(); ProjectDB.Instance.AddProject(null).ReturnsForAnyArgs(true); ProjectDB.Instance .WhenForAnyArgs(p => p.AddProject(null)) .Do(p => { isCalled = true; }); ProjectDB.Instance.GetProjects().Returns(new List <Project>()); ProjectDB.Instance .When(p => p.GetProjects()) .Do(p => { isCalled = true; }); ProjectDB.Instance.MarkProjectEnded(projectTest).Returns(true); ProjectDB.Instance.SetOcToProject(projectTest.Name, ocTestH.Id).ReturnsForAnyArgs(true); ProjectDB.Instance .WhenForAnyArgs(p => p.SetOcToProject(null, ocTestH.Id)) .Do(p => { isCalled = true; }); ProjectDB.Instance.GetProjectUserStory(projectTest.Name).ReturnsForAnyArgs(new List <UserStory>()); ProjectDB.Instance .WhenForAnyArgs(p => p.GetProjectUserStory(projectTest.Name)) .Do(p => { isCalled = true; }); ProjectDB.Instance.GetProjectPendingUserStory(projectTest.Name).ReturnsForAnyArgs(new List <UserStory>()); ProjectDB.Instance .WhenForAnyArgs(p => p.GetProjectPendingUserStory(projectTest.Name)) .Do(p => { isCalled = true; }); ProjectDB.Instance.GetProjects(hiringCompanyTest.IDHc).ReturnsForAnyArgs(new List <Project>()); ProjectDB.Instance .WhenForAnyArgs(p => p.GetProjects(hiringCompanyTest.IDHc)) .Do(p => { isCalled = true; }); #endregion ProjectDB #region OcCompanyDB OCompanyDB.Instance = Substitute.For <IOCompanyDB>(); OCompanyDB.Instance.AddOutsourcingCompany(ocTestH).ReturnsForAnyArgs(true); OCompanyDB.Instance.AddOutsourcingCompany(null).Returns(false); OCompanyDB.Instance .WhenForAnyArgs(p => p.AddOutsourcingCompany(null)) .Do(p => { isCalled = true; }); OCompanyDB.Instance.GetOutsourcingCompany(ocTest_common.Name).Returns(ocTestH); OCompanyDB.Instance .WhenForAnyArgs(p => p.GetOutsourcingCompany(null)) .Do(p => { isCalled = true; }); OCompanyDB.Instance.GetOutsourcingCompanies().Returns(new List <OutsourcingCompany>()); OCompanyDB.Instance .When(p => p.GetOutsourcingCompanies()) .Do(p => { isCalled = true; }); #endregion OcCompanyDB #region PartnershipDB PartnershipDB.Instance = Substitute.For <IPartnershipDB>(); PartnershipDB.Instance.AddPartnership(hiringCompanyTest, ocTestH).Returns(true); PartnershipDB.Instance .WhenForAnyArgs(p => p.AddPartnership(null, null)) .Do(p => { isCalled = true; }); PartnershipDB.Instance.GetPartnerOc(hiringCompanyTest.IDHc).Returns(new List <OutsourcingCompany>() { ocTestH }); PartnershipDB.Instance .WhenForAnyArgs(p => p.GetPartnerOc(hiringCompanyTest.IDHc)) .Do(p => { isCalled = true; }); PartnershipDB.Instance.GetPartnershipProjects(hiringCompanyTest.IDHc).Returns(new List <Project>()); PartnershipDB.Instance .WhenForAnyArgs(p => p.GetPartnershipProjects(hiringCompanyTest.IDHc)) .Do(p => { isCalled = true; }); #endregion PartnershipDB #region UserStoryDB UserStoryDB.Instance = Substitute.For <IUserStoryDB>(); UserStoryDB.Instance.GetUserStory(null).ReturnsForAnyArgs(new List <UserStory>()); UserStoryDB.Instance.GetUserStory(projectTest.Name).Returns(new List <UserStory>() { us }); UserStoryDB.Instance .WhenForAnyArgs(p => p.GetUserStory(null)) .Do(p => { isCalled = true; }); UserStoryDB.Instance.AddUserStory(us).ReturnsForAnyArgs(true); UserStoryDB.Instance .WhenForAnyArgs(p => p.AddUserStory(null)) .Do(p => { isCalled = true; }); UserStoryDB.Instance.ChangeUserStoryState(projectTest.Id, UserStoryState.Approved).ReturnsForAnyArgs(true); UserStoryDB.Instance .WhenForAnyArgs(p => p.ChangeUserStoryState(projectTest.Id, UserStoryState.Approved)) .Do(p => { isCalled = true; }); UserStoryDB.Instance.GetUserStoryFromId(1).Returns(us); UserStoryDB.Instance .WhenForAnyArgs(p => p.GetUserStoryFromId(1)) .Do(p => { isCalled = true; }); #endregion UserStoryDB #region ServiceProxy ServiceProxy.Instance = Substitute.For <IOcContract>(); ServiceProxy.Instance.SendOcRequest(1, null).ReturnsForAnyArgs(true); ServiceProxy.Instance.SendProject(hiringCompanyTest.IDHc, ocTestH.Id, null).ReturnsForAnyArgs(true); ServiceProxy.Instance.SendUserStory(null).ReturnsForAnyArgs(true); ServiceProxy.Instance.GetUserStoryes(projectTest.Name).Returns(new List <WcfCommon.Data.UserStory>() { new WcfCommon.Data.UserStory() { Name = "us1", Description = "Opis", Progress = 70, Id = 1, UserStoryState = WcfCommon.Enums.UserStoryState.Proposed, WeightOfUserStory = 5 } }); ServiceProxy.Instance.GetProjects(hiringCompanyTest.IDHc).Returns(new List <WcfCommon.Data.Project>() { new WcfCommon.Data.Project() { Name = "p1", Approved = true, Description = "Opis", EndDate = DateTime.Now, StartDate = DateTime.Now, Ended = false, Progress = 60 } }); #endregion ServiceProxy }