public void TestUpdatePersonalInfo() { var mockSet = new Mock <DbSet <PersonalInfo> >(); var mockContext = new Mock <LibraryContext>(); mockContext.Setup(x => x.Set <PersonalInfo>()).Returns(mockSet.Object); this.personalInfo.PhoneNumber = "0731233234"; this.service = new PersonalInfoService(mockContext.Object); var result = this.service.Update(this.personalInfo); try { mockSet.Verify(m => m.Attach(It.IsAny <PersonalInfo>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); } catch (MockException e) { Assert.Fail(e.Message); } Assert.IsNotNull(result); Assert.IsTrue(result.IsValid); Assert.IsTrue(result.Errors.Count == 0); }
public void TestGetAllPersonalInfos() { var data = new List <PersonalInfo> { this.personalInfo, new PersonalInfo { Email = "*****@*****.**", PhoneNumber = "0722662278" } }.AsQueryable(); var mockSet = new Mock <DbSet <PersonalInfo> >(); mockSet.As <IQueryable <PersonalInfo> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <PersonalInfo> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <PersonalInfo> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <PersonalInfo> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <LibraryContext>(); mockContext.Setup(x => x.Set <PersonalInfo>()).Returns(mockSet.Object); this.service = new PersonalInfoService(mockContext.Object); var authors = this.service.GetAll(); Assert.IsNotNull(authors); Assert.AreEqual(authors.Count(), 2); }
public void TestDeletePersonalInfo() { var mockSet = new Mock <DbSet <PersonalInfo> >(); var mockContext = new Mock <LibraryContext>(); mockContext.Setup(x => x.Set <PersonalInfo>()).Returns(mockSet.Object); this.service = new PersonalInfoService(mockContext.Object); this.service.Delete(this.personalInfo); try { mockSet.Verify(m => m.Remove(It.IsAny <PersonalInfo>()), Times.Once()); } catch (MockException e) { Assert.Fail(e.Message); } }
private void LoadPersonalInfo() { #if DEBUG Trace.WriteLine(message: "LoadPersonalInfo"); #endif PersonalInfoService service = new PersonalInfoService(); List <PersonalInfoModel> list = service.CreateModels(); if (list == null) { throw new NullReferenceException(message: "Unable to load xml data from service"); } foreach (var item in list) { _personalInfoModels.Add(item: item); } _educationDescription = service.LoadDescriptionData(field: "Education"); _hobbiesDescription = service.LoadDescriptionData(field: "Hobbies"); _skillsDescription = service.LoadDescriptionData(field: "Skills"); _workExperienceDescription = service.LoadDescriptionData(field: "WorkExperience"); }