public void Products() { var sut = new MruProductsImpl(new List<Guid> { products[1].Id, products[2].Id }, factories); var expected = new Product[] { products[1], products[2] }; var actual = sut.Products; Assert.AreEqual(expected, actual); }
public void AddProduct(Product product) { if (productIds.Contains(product.Id)) productIds.Remove(product.Id); productIds.Insert(0, product.Id); var maxCount = GetMaxCount(); while (productIds.Count > maxCount) productIds.RemoveAt(maxCount); }
public void TestInitialize() { factories = Substitute.For<Factories>(); fixture = new Fixture(); factories.Categories.Returns(fixture.CreateMany<Category>().ToList()); categories = factories.Categories.Select(category => new CategoryViewModel(category, factories)).ToList(); product = new Product { CategoryId = factories.Categories.First().Id }; product.SetOwner(factories); overrideCategory = new CategoryViewModel(new Category(), factories); }
public void ProductsNeverExceedTheCurrentMaxCount() { var initialProductIds = new List<Guid> { Guid.NewGuid(), products[1].Id, products[2].Id }; settings.MruProductMaxCount = 1; var sut = new MruProductsImpl(initialProductIds, factories); var expected = new Product[] { products[1] }; var actual = sut.Products; Assert.AreEqual(expected, actual); Assert.AreEqual(initialProductIds.Count, 3); }
public void TestInitialize() { factories = new FactoriesImpl(); factories.StorageCreator = new StorageCreatorStub(); product = factories.CreateProduct(); product.EnergyPer100g = 100; product.EnergyPerServing = 100; var meal = factories.CreateMeal(); item = meal.AddItem(); item.ProductId = product.Id; sut = new MealItemViewModel(item, factories); gram = Unit.Gram.GetAbbreviation(); mililiter = Unit.Mililiter.GetAbbreviation(); servingSize = () => Unit.ServingSize.GetAbbreviationOrServingSizeDetalis(product); ounce = Unit.Ounce.GetAbbreviation(); pound = Unit.Pound.GetAbbreviation(); }
private void SetupProducts() { var product = new Product(); product.SetOwner(factories); product.Id = Guid.NewGuid(); product.AddedByUser = true; factories.Products.Returns(new List<Product> { product }); factories.CreateProduct().Returns(_ => { factories.Products.Add(product); return product; }); }
public MaxCuAndFpuInCategories(Finder finder, Product replacement) { this.finder = finder; this.replacement = replacement; }
public ProductViewModel(Product product) { Product = product; autoCalculatingEnergyPer100g = Product.EnergyPer100g == 0; autoCalculatingEnergyPerServing = Product.EnergyPerServing == 0; }
public static Unit TryGetValueOfAbbreviationOrServingSizeDetalis(this Unit caller, string abbreviation, Product servingSizeInfo) { var servingSizeDetalisOfServingSize = Unit.ServingSize. GetAbbreviationOrServingSizeDetalis(servingSizeInfo); if (abbreviation == servingSizeDetalisOfServingSize) { return Unit.ServingSize; } return caller.TryGetValueOfAbbreviation(abbreviation); }
public static List<string> GetAbbreviationsOrServingSizeDetalisFiltered(Func<Unit, bool> filterIn, Product servingSizeInfo) { var abbreviations = new List<string>(); var units = MyEnum.GetValues<Unit>(); foreach (var unit in units) { if (filterIn(unit)) { abbreviations.Add(unit.GetAbbreviationOrServingSizeDetalis(servingSizeInfo)); } } return abbreviations; }
public static string GetAbbreviationOrServingSizeDetalis(this Unit unit, Product servingSizeInfo) { if (unit == Unit.ServingSize) { var desc = GetAbbreviationOrServingSizeDesc(unit, servingSizeInfo); var value = servingSizeInfo.ServingSizeValue; var valueUnit = servingSizeInfo.ServingSizeUnit; return string.Format("{0} {1} {2}", desc, value, valueUnit.GetAbbreviation()); } return unit.GetAbbreviation(); }
public static string GetAbbreviationOrServingSizeDesc(this Unit unit, Product servingSizeInfo) { var desc = servingSizeInfo.ServingSizeDescription; var descPresent = !string.IsNullOrEmpty(desc); if (unit == Unit.ServingSize && descPresent) { return desc; } return unit.GetAbbreviation(); }
public void ProductsWhenProductDoesNotExistSkipsIt() { var sut = new MruProductsImpl(new List<Guid> { Guid.NewGuid(), products[3].Id }, factories); var expected = new Product[] { products[3] }; var actual = sut.Products; Assert.AreEqual(expected, actual); }
public void TestInitialize() { factories = Substitute.For<Factories>(); messageDialog = Substitute.For<MessageDialog>(); learningCuAndFpu = Substitute.For<LearningCuAndFpu>(); sut = new ProductEditingViewModel(factories, new BackgroundWorkerSyncFactory(), messageDialog, learningCuAndFpu); sut.Navigator = Substitute.For<Navigator>(); sut.Init(new ProductEditingViewModel.Navigation()); product = new Product { Name = "Foo" }; factories.Finder.FindProductById(Guid.Empty).Returns(product); factories.Categories.Returns(new List<Category> { new Category(), new Category() }); }