/// <summary> /// The test method for GetSocialRelationshipsByContact success /// </summary> public void Mock_SocialRelationship() { var mock = new Mock <ISocialRelationshipRuleEngine>(); socialRelationhshipRuleEngine = mock.Object; socialRelationshipController = new SocialRelationshipController(socialRelationhshipRuleEngine); socialRelationships = new List <SocialRelationshipModel>(); socialRelationships.Add(new SocialRelationshipModel() { SocialRelationshipID = 1, ContactID = 1, EncounterID = null, ReviewedNoChanges = false, TakenBy = 1, TakenTime = DateTime.Now, IsActive = true, ModifiedBy = 5, ModifiedOn = DateTime.Now, ForceRollback = true }); var socialRelationshipResponse = new Response <SocialRelationshipModel>() { DataItems = socialRelationships }; //Get Social Relationship mock.Setup(r => r.GetSocialRelationshipsByContact(It.IsAny <long>())) .Callback((long id) => { socialRelationshipResponse.DataItems = socialRelationships.Where(sr => sr.ContactID == id).ToList(); }) .Returns(socialRelationshipResponse); //Add Social Relationship mock.Setup(r => r.AddSocialRelationship(It.IsAny <SocialRelationshipModel>())) .Callback((SocialRelationshipModel socialRelationModel) => { if (socialRelationModel.ContactID > 0) { socialRelationships.Add(socialRelationModel); } }) .Returns(socialRelationshipResponse); //Update Social Relationship mock.Setup(r => r.UpdateSocialRelationship(It.IsAny <SocialRelationshipModel>())) .Callback((SocialRelationshipModel socialRelationModel) => { if (socialRelationModel.SocialRelationshipID > 0) { socialRelationships.Remove(socialRelationships.Find(sr => sr.SocialRelationshipID == socialRelationModel.SocialRelationshipID)); socialRelationships.Add(socialRelationModel); } }) .Returns(socialRelationshipResponse); //Delete Social Relationship var deleteResponse = new Response <SocialRelationshipModel>(); mock.Setup(r => r.DeleteSocialRelationship(It.IsAny <long>(), DateTime.UtcNow)) .Callback((long id) => socialRelationships.Remove(socialRelationships.Find(sr => sr.SocialRelationshipID == id))) .Returns(deleteResponse); }
/// <summary> /// Initializes a new instance of the <see cref="SocialRelationshipsController"/> class. /// </summary> /// <param name="socialRelationshipRuleEngine">The srh rule engine.</param> public SocialRelationshipController(ISocialRelationshipRuleEngine socialRelationshipRuleEngine) { this._socialRelationshipRuleEngine = socialRelationshipRuleEngine; }