public void DeleteReaderUsingSurnameTest() { Assert.IsTrue(ReaderService.AddReader("Sharoon", "Steel")); //delete to restore original db Assert.IsTrue(ReaderService.DeleteReader("Sharoon", "Steel")); }
public void TestUpdateReader() { var mockSet = new Mock <DbSet <Reader> >(); var mockContext = new Mock <LibraryContext>(); mockContext.Setup(x => x.Set <Reader>()).Returns(mockSet.Object); this.reader.FirstName = "Update"; this.service = new ReaderService(mockContext.Object); var result = this.service.Update(this.reader); try { mockSet.Verify(m => m.Attach(It.IsAny <Reader>()), 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 async Task ReaderService_AddAsync_AddModel() { //arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(m => m.ReaderRepository.AddAsync(It.IsAny <Reader>())); var readerService = new ReaderService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile()); var newReader = new ReaderModel() { Id = 10, Name = "Test_Adding", Email = "*****@*****.**", Phone = "123789456", Address = "Kyiv, 10" }; //act await readerService.AddAsync(newReader); //assert mockUnitOfWork.Verify(x => x.ReaderRepository.AddAsync( It.Is <Reader>(r => r.Id == newReader.Id && r.Name == newReader.Name && r.Email == newReader.Email && r.ReaderProfile.Phone == newReader.Phone && r.ReaderProfile.Address == newReader.Address)), Times.Once); mockUnitOfWork.Verify(x => x.SaveAsync(), Times.Once); }
public void ReaderService_UpdateAsync_ThrowsExceptionIfModelIsIncorrect() { //arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(m => m.ReaderRepository.Update(It.IsAny <Reader>())); var readerService = new ReaderService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile()); // Name is empty var reader = new ReaderModel { Id = 1, Name = "", Email = "*****@*****.**", Phone = "999999999", Address = "Glasgow" }; Assert.ThrowsAsync <LibraryException>(async() => await readerService.UpdateAsync(reader)); // Email is empty reader.Name = "Scrooge McDuck"; reader.Email = ""; Assert.ThrowsAsync <LibraryException>(async() => await readerService.UpdateAsync(reader)); // Phone is empty reader.Email = "*****@*****.**"; reader.Phone = ""; Assert.ThrowsAsync <LibraryException>(async() => await readerService.UpdateAsync(reader)); // Address is empty reader.Phone = "999999999"; reader.Address = ""; Assert.ThrowsAsync <LibraryException>(async() => await readerService.UpdateAsync(reader)); }
public void ReaderService_GetReadersThatDontReturnBooks_ReaderModels() { //arrange var expected = GetTestReaderModels().ToList(); expected.RemoveAt(expected.Count - 1); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(m => m.ReaderRepository.GetAllWithDetails()) .Returns(GetTestReaderEntities().AsQueryable()); mockUnitOfWork .Setup(m => m.HistoryRepository.FindAll()) .Returns(GetTestHistoryEntities().AsQueryable()); mockUnitOfWork .Setup(m => m.CardRepository.FindAll()) .Returns(GetTestCardEntities().AsQueryable()); var readerService = new ReaderService(mockUnitOfWork.Object, UnitTestHelper.CreateMapperProfile()); //act var actual = readerService.GetReadersThatDontReturnBooks().ToList(); //assert Assert.IsInstanceOf <IEnumerable <ReaderModel> >(actual); Assert.AreEqual(expected.Count, actual.Count); for (int i = 0; i < expected.Count; i++) { var expectedReaderModel = expected[i]; var actualReaderModel = actual[i]; Assert.IsTrue(_readerModelComparer.Equals(expectedReaderModel, actualReaderModel)); } }
public void AddReaderToDatabaseTest() { Assert.IsTrue(ReaderService.AddReader("Sharoon", "Steel")); //delete to restore original db Assert.IsTrue(ReaderService.DeleteReader("Sharoon", "Steel")); }
public IHttpActionResult Delete(int readerID, int bookID) { BookService bookService = new BookService(); ReaderService readerService = new ReaderService(); // check if the reader really exists Reader reader = readerService.GetReaderByID(readerID); if (reader == null) { return(BadRequest($"invalid readerID: {readerID}")); } // check if the book really exists Book book = bookService.GetBookByID(bookID); if (reader == null) { return(BadRequest($"invalid bookID: {bookID}")); } readerService.ReturnBook(readerID, bookID); return(Ok()); }
public void ReturnBookEventForWrongReaderTest() { Book book = BookService.GetBook("Harry Potter", "J.K. Rowling"); Reader reader = ReaderService.GetReader("Charilize", "Padilla"); EventService.ReturnBookByReader(book, reader); }
public void BorrowBookNonExisitingBookTest() { Book book = BookService.GetBook("Harry Potter part 2", "J.K. Rowling"); Reader reader = ReaderService.GetReader("Judith", "Rojas"); EventService.BorrowBookForReader(book, reader); }
private static void ReadInput() { IreaderService reader = new ReaderService(); ICalculateMMSAndSMSFeeService SMSAndMMSFee = new CalculateMMSAndSMSFeeService(); var builder = new CalculateInvoiceBuilderService(reader, SMSAndMMSFee); while (true) { try { builder .AddMontlyFee() .AddSendedSMS() .AddSendedMMS() .AddMinutesToA1NotInThePacket() .AddMinutesToTelenorNotInThePacket() .AddMinutesToVivacomNotInThePacket() .AddMinutesRouming() .AddUsedMBInCountryNotInThePacket() .AddUsedMBInEuropeanUnionNotInThePacket() .AddUsedMBOutsideEuropeanUnionNotInThePacket() .AddOtherTaxes() .AddDiscount() .Result(); Console.WriteLine(GlobalConstants.GlobalConstants.Delimiter); } catch (Exception e) { Console.WriteLine(GlobalConstants.GlobalConstants.ErrorNotSupportedFormat); Console.WriteLine(GlobalConstants.GlobalConstants.Delimiter); } } }
public void TestGetAllReaders() { var data = new List <Reader> { this.reader, new Reader { Address = "str 124521332", FirstName = "aaa", LastName = "bbb", Id = 1, ReaderPersonalInfoId = 1 } }.AsQueryable(); var mockSet = new Mock <DbSet <Reader> >(); mockSet.As <IQueryable <Reader> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Reader> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Reader> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Reader> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <LibraryContext>(); mockContext.Setup(x => x.Set <Reader>()).Returns(mockSet.Object); this.service = new ReaderService(mockContext.Object); var pubs = this.service.GetAll(); Assert.IsNotNull(pubs); Assert.AreEqual(pubs.Count(), 2); }
public MainWindow() { InitializeComponent(); DataContext = MainModel = new Model(); var fonts = Fonts.SystemFontFamilies.OrderBy(f => f.Source).ToList(); var sizes = new List <double>() { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 96 }; var magnifierTypes = Enum.GetNames(typeof(MagnifierType)).ToList(); CmbFontFamily.ItemsSource = fonts; CmbFontFamily.SelectedIndex = fonts.FindIndex(f => f.Source == "Arial"); CmbFontSize.ItemsSource = sizes; CmbFontSize.SelectedIndex = sizes.IndexOf(18); CmbLineHeight.ItemsSource = sizes; CmbLineHeight.SelectedIndex = sizes.IndexOf(22); CmbMagnifier.ItemsSource = magnifierTypes; CmbMagnifier.SelectedIndex = magnifierTypes.IndexOf(Reader.MagnifierType.ToString()); BtnLoadSample.Checked += delegate { BtnLoadSampleChecking(); }; BtnLoadSample.Unchecked += delegate { BtnLoadSampleChecking(); }; ReaderService = new ReaderService { PixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip, ContentProvider = new ContentProvider(Path.Combine(Environment.CurrentDirectory, "Data\\LtrSample.html"), false) }; DpiChanged += delegate { ReaderService.PixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip; }; Loaded += delegate { BtnLoadSampleChecking(); }; }
public override IAnimal Create() { var tuple = AnimalParams(); float height = tuple.Item1; float weight = tuple.Item2; string eyeColor = tuple.Item3; NotificationService.Write("Введите имя: "); string name = ReaderService.ReadLine(); NotificationService.Write("Введите породу: "); string breed = ReaderService.ReadLine(); bool isItWooled = BoolEnter("У нее есть шерсть?"); string coatColor; if (isItWooled) { NotificationService.Write("Введите цвет шерсти: "); coatColor = ReaderService.ReadLine(); } else { coatColor = "Шерсти нет"; } bool isItVaccinated = BoolEnter("У нее есть прививки?"); DateTime birthDate = (DateTime)DateEnter("Введите дату рождения"); return(new Cat(height, weight, eyeColor, name, breed, isItVaccinated, coatColor, birthDate, isItWooled, SoundService)); }
public ServicesManager(DataManager dataManager) { _dataManager = dataManager; _bookService = new BookService(dataManager); _readerService = new ReaderService(dataManager); _authorService = new AuthorService(dataManager); _logService = new LogService(dataManager); }
protected override BaseReader GetOperationParameters( ReaderService service, Stream inPartStream, Stream outPartStream, int partIndex) { return(new CompressionReader(service, inPartStream, outPartStream, partIndex)); }
protected override void OnStart(string[] args) { IReaderService readerService = new ReaderService(); IWSListener listener = new WSListener(readerService); _watcher.LogEvent += m => listener.Log(m); _watcher.Start(); }
public MainWindow(/*Generator generator*/) { InitializeComponent(); ReaderService reader = new ReaderService(); ParserService parser = new ParserService(); generator = new XmlGeneratorService(reader, parser); }
public ReaderListViewModel() { readerService = new ReaderService(); eventService = new EventService(); bookService = new BookService(); AddReader = new CommandBase(o => { ShowAddReaderView(); }, o => true); RefreshReaders(); }
public void GetReaderTest() { Reader reader = ReaderService.GetReader("Judith", "Rojas"); Assert.AreEqual(reader.reader_f_name, "Judith"); Assert.AreEqual(reader.reader_l_name, "Rojas"); Assert.IsNotNull(reader); }
public void AddReaderToDatabaseTest() { Assert.IsTrue(ReaderService.AddReader("Sharoon", "Steel")); Assert.AreEqual(ReaderService.GetAllReadersNumber(), 6); //delete to restore original db Assert.IsTrue(ReaderService.DeleteReader("Sharoon", "Steel")); }
protected BaseReader(ReaderService service, Stream inStream, Stream outStream, int partIndex) { this.service = service; this.inStream = inStream; this.outStream = outStream; this.partIndex = partIndex; }
public IList <ReaderModel> GetAll() { ReaderService ReaderService = new ReaderService(); var allReaders = ReaderService.GetAll() .Select(c => new ReaderModel(c)) .ToList(); return(allReaders); }
public Service() { Instance = this; this.displayResponder = new DisplayResponder(); this.reader = new ReaderService(); this.settings = Properties.Settings.Default; this.socket = new serviceSocket("127.0.0.1", 2345); this.ConnectViewModel = new ConnectViewModel(this.reader, this.settings); this.MainViewModel = new MainViewModel(this.displayResponder, this.reader.Commander, this.settings, this.socket); }
public void BorrowBookEventTest() { Book book = BookService.GetBook("Harry Potter", "J.K. Rowling"); Reader reader = ReaderService.GetReader("Judith", "Rojas"); Assert.AreEqual(book.quantity, 3); EventService.BorrowBookForReader(book, reader); Assert.AreEqual(book.quantity, 2); }
public TestSideBarElement(ReaderService readerService, SideBarElementType type, string text, string icon, string linkAddr, string tabGuid) { ReaderService = readerService; Type = type; _text = text; _icon = icon; _linkAddress = linkAddr; _tabGuid = tabGuid; }
public BorrowBookListViewModel() { readerService = new ReaderService(); bookService = new BookService(); BorrowBook = new CommandBase(o => { BorrowBookForReader(); }, o => true); ReturnBook = new CommandBase(o => { ReturnBookByReader(); }, o => true); RefreshReaders(); RefreshBooks(); }
public ReaderListViewModel() { readerService = new ReaderService(); eventService = new EventService(); bookService = new BookService(); AddReaderCommand = new CommandBase(ShowAddNewReader); EditReaderCommand = new CommandBase(ShowEditReader); RefreshReadersCommand = new CommandBase(RefreshReaders); DeleteReaderCommand = new CommandBase(DeleteReader); RefreshReaders(); }
public void BorrowBookQuantityEqualTo0Test() { BookService.AddBook("a", "t", 1999, "g", 0); Book book = BookService.GetBook("t", "a"); Reader reader = ReaderService.GetReader("Judith", "Rojas"); Assert.AreEqual(book.quantity, 0); EventService.BorrowBookForReader(book, reader); Assert.AreEqual(book.quantity, 0); }
public void StartWatching(string pathFile) { var manager = Configurator.CreateManager(new DependencyManager()); _watcher = manager.CreateWatcher(pathFile); _watcher.LogEvent += s => Console.WriteLine(s); _watcher.Start(); IReaderService readerService = new ReaderService(); IWatcherListener listener = new WatcherListener(readerService); _watcher.Created += m => listener.OnCreated(m); }
public void start(MainViewModel viewModel, ReaderService reader, MainForm mainform, CancellationToken ct) { this.viewModels = viewModel; this.reader = reader; this.mainform = mainform; _socket.Bind(_endPoint); //绑定端口 _socket.Listen(BACKLOG); //开启监听 //Thread acceptServer = new Thread(AcceptWork); //开启新线程处理监听 //acceptServer.IsBackground = true; //acceptServer.Start(); AcceptWork(ct); }