public void when_creating_duplicate_named_product_then_throws()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>(c => c.Find("SimpleToolkit") ==
                    Mock.Of<IToolkitInfo>(t => t.Products == new[]
                    {
                        Mock.Of<IProductInfo>(p =>
                            p.Toolkit == Mock.Of<IToolkitInfo>() &&
                            p.SchemaId == "NuPattern.Tookit.Simple.IAmazonWebServices")
                    })));

            store.CreateProduct("Foo", "SimpleToolkit", typeof(IAmazonWebServices).ToTypeFullName());

            Assert.Throws<ArgumentException>(() =>
                store.CreateProduct("Foo", "SimpleToolkit", typeof(IAmazonWebServices).ToTypeFullName()));
        }
        public override void Execute(object parameter)
        {
            Product product = new Product()
            {
                Name     = _viewModel.ProductName,
                Quantity = _viewModel.ProductQuantity,
                Price    = _viewModel.ProductPrice
            };

            _productStore.CreateProduct(product);
        }
        public void when_creating_product_then_store_forwards_events_until_delete()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>(c => c.Find("SimpleToolkit") == Mock.Of<IToolkitInfo>(t => t.Products == new[]
                    {
                        Mock.Of<IProductInfo>(p =>
                            p.Toolkit == Mock.Of<IToolkitInfo>(i => i.Id == "SimpleToolkit" && i.Version == "1.0") &&
                            p.SchemaId == typeof(IAmazonWebServices).FullName &&
                            p.Components == new []
                            {
                                Mock.Of<IElementInfo>(e =>
                                    e.SchemaId == typeof(IStorage).FullName &&
                                    e.DefaultName == "Storage" &&
                                    e.Properties == new []
                                    {
                                        Mock.Of<IPropertyInfo>(ak => ak.Name == "RefreshOnLoad" && ak.PropertyType == typeof(bool)),
                                    }
                                )
                            } &&
                            p.Properties == new []
                            {
                                Mock.Of<IPropertyInfo>(ak => ak.Name == "AccessKey" && ak.PropertyType == typeof(string)),
                                Mock.Of<IPropertyInfo>(ak => ak.Name == "SecretKey" && ak.PropertyType == typeof(string)),
                            })
                    })));

            var created = default(IProduct);
            store.ProductEvents.Created += (sender, args) => created = args.Value;

            var product = store.CreateProduct("Simple", "SimpleToolkit", typeof(IAmazonWebServices).FullName);

            Assert.Same(product, created);

            product.Delete();
        }
        public void when_creating_product_on_disposed_store_then_throws()
        {
            var store = new ProductStore(
                "ProductStoreFixture.Simple.json",
                new JsonProductSerializer(),
                Mock.Of<IToolkitCatalog>());

            store.Dispose();

            Assert.Throws<ObjectDisposedException>(() => store.CreateProduct("foo", "bar", "baz"));
        }