public void Mock_EmergencyContact_Failure() { Mock <IEmergencyContactRuleEngine> mock = new Mock <IEmergencyContactRuleEngine>(); emergencyContactRuleEngine = mock.Object; emergencyContactController = new EmergencyContactController(emergencyContactRuleEngine); var emergencyContactFailure = new List <EmergencyContactModel>(); emergencyContactFailure.Add(new EmergencyContactModel() { ParentContactID = -1, ContactID = -1, ContactTypeID = -1, FirstName = "firstName", LastName = "lastName", GenderID = 1, DOB = DateTime.Now, SuffixID = 2, ContactRelationshipID = 1, RelationshipTypeID = 2, IsActive = true, ModifiedBy = 5, ModifiedOn = DateTime.Now, ForceRollback = true }); var allEmergencyContact = new Response <EmergencyContactModel>() { DataItems = emergencyContactFailure }; //Get EmergencyContacts Response <EmergencyContactModel> emergencyContactsResponse = new Response <EmergencyContactModel>(); emergencyContactsResponse.DataItems = emergencyContactFailure.Where(contact => contact.ParentContactID == _defaultContactId && contact.ContactTypeID == _defaultContactTypeId).ToList(); mock.Setup(r => r.GetEmergencyContacts(It.IsAny <long>(), It.IsAny <int>())) .Returns(emergencyContactsResponse); //Add EmergencyContact mock.Setup(r => r.AddEmergencyContact(It.IsAny <EmergencyContactModel>())) .Callback((EmergencyContactModel emergencyContactModel) => emergencyContactFailure.Add(emergencyContactModel)) .Returns(allEmergencyContact); //Update EmergencyContact mock.Setup(r => r.UpdateEmergencyContact(It.IsAny <EmergencyContactModel>())) .Callback((EmergencyContactModel emergencyContactModel) => emergencyContactFailure.Add(emergencyContactModel)) .Returns(allEmergencyContact); //Delete EmergencyContact Response <EmergencyContactModel> deleteResponse = new Response <EmergencyContactModel>(); deleteResponse.RowAffected = 1; deleteResponse.DataItems = emergencyContactFailure; mock.Setup(r => r.DeleteEmergencyContact(It.IsAny <long>(), DateTime.UtcNow)) .Callback((long id) => emergencyContactFailure.Remove(emergencyContactFailure.Find(deleteEmergencyContact => deleteEmergencyContact.ContactID == id))) .Returns(deleteResponse); }
/// <summary> /// constructor /// </summary> /// <param name="emergencyContactRuleEngine"></param> public EmergencyContactController(IEmergencyContactRuleEngine emergencyContactRuleEngine) { this.emergencyContactRuleEngine = emergencyContactRuleEngine; }