private void button_Click(object sender, RoutedEventArgs e) { Data data = new Data() { Name = nameTextBox.Text, Address = addressTextBox.Text, Company = companyTextBox.Text, Surname = surnameTextBox.Text, Patronymic = patronymicTextBox.Text, Occupation = occupationBox.Text, Number = numberTextBox.Text }; bool valid = FieldsValidation(data, typeBox.SelectedIndex); service.AddPhone(typeBox.SelectedIndex, service.IsDublicate(numberTextBox.Text), data, valid); }
public void IsDublicate_ExistNumberInSecondTable_ReturnTrue() { var data1 = new List <CorporativeTelephone> { new CorporativeTelephone { PhoneNumber = "1234567890000" }, new CorporativeTelephone { PhoneNumber = "1234567890001" } }.AsQueryable(); var data2 = new List <PersonalTelephone> { new PersonalTelephone { PhoneNumber = "1234567890000" }, new PersonalTelephone { PhoneNumber = "1234567890001" } }.AsQueryable(); var mockSetC = new Mock <DbSet <CorporativeTelephone> >(); mockSetC.As <IQueryable <CorporativeTelephone> >().Setup(m => m.Provider).Returns(data1.Provider); mockSetC.As <IQueryable <CorporativeTelephone> >().Setup(m => m.Expression).Returns(data1.Expression); mockSetC.As <IQueryable <CorporativeTelephone> >().Setup(m => m.ElementType).Returns(data1.ElementType); mockSetC.As <IQueryable <CorporativeTelephone> >().Setup(m => m.GetEnumerator()).Returns(data1.GetEnumerator()); var mockSetP = new Mock <DbSet <PersonalTelephone> >(); mockSetP.As <IQueryable <PersonalTelephone> >().Setup(m => m.Provider).Returns(data2.Provider); mockSetP.As <IQueryable <PersonalTelephone> >().Setup(m => m.Expression).Returns(data2.Expression); mockSetP.As <IQueryable <PersonalTelephone> >().Setup(m => m.ElementType).Returns(data2.ElementType); mockSetP.As <IQueryable <PersonalTelephone> >().Setup(m => m.GetEnumerator()).Returns(data2.GetEnumerator()); var mockContext = new Mock <PhoneContext>(); mockContext.Setup(m => m.CorpPhones).Returns(mockSetC.Object); mockContext.Setup(m => m.PersPhone).Returns(mockSetP.Object); AddService service = new AddService(mockContext.Object); bool result = service.IsDublicate("1234567890001"); Assert.IsTrue(result); }