public void Initialize() { TEST_QUANTITY = 5; TEST_ADD_QUANTITY = 4; TEST_CAT_NAME = "testowa kategoria"; testCategory = new Category(); testCategory.Name = TEST_CAT_NAME; testBook = new BookType(); testGetBook = new BookType(); testBook.Id = 47123; testBook.Title = "Książka testowa"; testBook.Authors = "Autor testowy"; testBook.Category = testCategory; testBook.QuantityMap = new QuantityMap(); testBook.QuantityMap.Quantity = TEST_QUANTITY; testBook.Price = 40; categoryList = new List <Category>(); bookTypeList = new List <BookType>(); booksInformationDaoMock = _factory.CreateMock <IBooksInformationDao>(); bis.BooksInformationDao = booksInformationDaoMock.MockObject; sms.BooksInformationDao = booksInformationDaoMock.MockObject; booksInformationDaoMock.Expects.One.MethodWith <IEnumerable <BookType> >(x => x.GetAllBooks()).WillReturn(bookTypeList); booksInformationDaoMock.Expects.One.MethodWith <IList <Category> >(x => x.GetAllCategories()).WillReturn(categoryList); booksInformationDaoMock.Expects.One.MethodWith <BookType>(x => x.GetBookTypeById(testBook.Id)).WillReturn(testBook); booksInformationDaoMock.Expects.One.MethodWith <BookType>(x => x.GetBookTypeById(testGetBook.Id)).WillReturn(testGetBook); storehouseManagementDaoMock = _factory.CreateMock <IStorehouseManagementDao>(); sms.StorehouseManagementDao = storehouseManagementDaoMock.MockObject; NMock.Actions.InvokeAction markSold = new NMock.Actions.InvokeAction(new Action(() => changeQuantity())); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.MarkSold(testBook.Id, testBook.QuantityMap.Quantity)).Will(markSold); storehouseManagementDaoMock.Expects.One.MethodWith <bool>(x => x.MarkSold(-1, 5)).WillReturn(false); NMock.Actions.InvokeAction saveCategory = new NMock.Actions.InvokeAction(new Action(() => categoryList.Add(testCategory))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveCategory(testCategory)).Will(saveCategory); NMock.Actions.InvokeAction saveBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveBookType(testBook)).Will(saveBookType); NMock.Actions.InvokeAction addCategory = new NMock.Actions.InvokeAction(new Action(() => categoryList.Add(testCategory))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.AddCategory(TEST_CAT_NAME)).Will(addCategory); NMock.Actions.InvokeAction addBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.AddBookType(testBook.Title, testBook.Authors, testBook.Price, TEST_QUANTITY, testBook.Category)).Will(addBookType); // NMock.Actions.InvokeAction addQuantity = new NMock.Actions.InvokeAction(new Action(() => quantityMap = new QuantityMap() { Quantity = 0 }; image = new BookImage() { URL = "" }; category = new Category() { }; }
public void Initialize() { CATEGORY_NAME = "Przygodowa"; BOOK_TITLE = "Robinson"; BOOK_AUTHORS = "A I B"; price = 100; quantityMap = new QuantityMap(); quantity = 10; quantityMap.Quantity = quantity; quantityMap.Id = 1; category = new Category(); category.Name = CATEGORY_NAME; bookType = new BookType(); bookType.Category = category; bookType.Title = BOOK_TITLE; bookType.Image = null; bookType.Price = price; bookType.Id = 1; bookType.Authors = BOOK_AUTHORS; bookTypeList = new List <BookType>(); categoryList = new List <Category>(); var bookInformationMock = _factory.CreateMock <IBooksInformationDao>(); bis.BooksInformationDao = bookInformationMock.MockObject; bookInformationMock.Expects.One.MethodWith <BookType>(x => x.GetBookTypeById(-1)).WillReturn(null); bookInformationMock.Expects.One.MethodWith <BookType>(x => x.GetBookTypeById(bookType.Id)).WillReturn(bookType); bookInformationMock.Expects.One.MethodWith <IEnumerable <BookType> >(x => x.GetAllBooks()) .WillReturn(bookTypeList); bookInformationMock.Expects.One.MethodWith <IList <Category> >(x => x.GetAllCategories()) .WillReturn(categoryList); bookInformationMock.Expects.One.MethodWith <IEnumerable <BookType> >(x => x.GetBooksByCategoryId(category.Id)) .WillReturn(bookTypeList); bookInformationMock.Expects.One.MethodWith <IEnumerable <BookType> >(x => x.GetBooksByCategoryId(-1)) .WillReturn(null); var storehouseManagementMock = _factory.CreateMock <IStorehouseManagementDao>(); sms.StorehouseManagementDao = storehouseManagementMock.MockObject; NMock.Actions.InvokeAction saveBookTypeAction = new NMock.Actions.InvokeAction( new Action(() => bookTypeList.Add(bookType))); storehouseManagementMock.Expects.Any.MethodWith(x => x.SaveBookType(bookType)).Will(saveBookTypeAction); NMock.Actions.InvokeAction saveCategoryAction = new NMock.Actions.InvokeAction( new Action(() => categoryList.Add(category))); storehouseManagementMock.Expects.Any.MethodWith(x => x.SaveCategory(category)).Will(saveCategoryAction); }
/// <summary> /// Initializes a new instance of the <see cref="MainViewModel"/> class. /// </summary> public MainViewModel() { _rengaApplication = new Renga.Application(); QuantityMap = new QuantityMap(); var types = new List <LocalizableObjectType> { new LocalizableObjectType(Guid.Empty) }; types.AddRange(typeof(Renga.ObjectTypes) .GetProperties() .Select(p => (Guid)p.GetValue(null)) .Select(guid => new LocalizableObjectType(guid))); ObjectTypes = types; _quantityIds = new List <Guid>(typeof(Renga.QuantityIds).GetProperties().Select(p => (Guid)p.GetValue(null))); ShowButtonVisibility = _rengaApplication.ActiveView.Type == Renga.ViewType.ViewType_View3D ? Visibility.Visible : Visibility.Collapsed; }
public void AddBookType(string title, string authors, decimal price, int quantity, Category category, string imageURL) { QuantityMap quantityMap = new QuantityMap() { Quantity = quantity }; BookImage image = new BookImage() { URL = imageURL }; BookType newBookType = new BookType() { Title = title, Authors = authors, Price = price, QuantityMap = quantityMap, Category = category, Image = image }; StorehouseManagementDao.SaveBookType(newBookType); }
/// <summary> /// Initializes a new instance of the <see cref="SearchData"/> class. /// </summary> /// <param name="searchValue">Исходная поисковая строка</param> /// <param name="matchType">Тип совпадения для строковых значений</param> /// <param name="quantityMap">Единицы получения величин</param> public SearchData(string searchValue, MatchType matchType, QuantityMap quantityMap) { _matchType = matchType; _lengthUnit = quantityMap.LengthUnit; _massUnit = quantityMap.MassUnit; _areaUnit = quantityMap.AreaUnit; _volumeUnit = quantityMap.VolumeUnit; _tolerance = quantityMap.Tolerance; _searchBoolValues = new List <Value>(); _searchDoubleValues = new List <Value>(); _searchIntValues = new List <Value>(); _searchStringValues = new List <Value>(); _searchValues = new List <string>(); foreach (var str in searchValue.Split('*')) { var s = str; var name = string.Empty; if (s.Contains("=")) { var split = s.Split('='); name = split[0]; s = split[1]; } var op = Operator.Equal; if (str.StartsWith("!=")) { op = Operator.NotEqual; s = str.Substring(2); } else if (str.StartsWith("<")) { op = Operator.Less; s = str.Substring(1); } else if (str.StartsWith(">")) { op = Operator.More; s = str.Substring(1); } var addString = true; if (int.TryParse(s, out var i)) { _searchIntValues.Add(new Value(op, s, i, name, matchType)); addString = false; } if (double.TryParse(s, out var d)) { _searchDoubleValues.Add(new Value(op, s, d, name, matchType)); addString = false; } if (bool.TryParse(s, out var b)) { _searchBoolValues.Add(new Value(op, s, b, name, matchType)); addString = false; } if (addString) { _searchStringValues.Add(new Value(op, s, name, matchType)); } _searchValues.Add(s); } }