예제 #1
0
        public async Task <OperationStatusInfo> AddSales(object addedSale)
        {
            return(await Task.Run(() =>
            {
                Dictionary <Type, object> collection = new Dictionary <Type, object>();
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);

                string attachedSaleObjectText = addedSale.ToString();
                Sale newSale = JsonConvert.DeserializeObject <Sale>(attachedSaleObjectText);
                AddSaleRequest addSaleRequest = new AddSaleRequest(newSale.Product, newSale.Count.ToString(),
                                                                   newSale.Datetime.ToString(), newSale.Price.ToString(), newSale.Seller);

                try
                {
                    AddSaleResponse addSaleResponse = hubEnvironment.UseCaseFactory
                                                      .Create <IUseCase <AddSaleRequest, AddSaleResponse> >()
                                                      .Execute(addSaleRequest);
                    collection.Add(typeof(List <Sale>), addSaleResponse.Sales);
                    collection.Add(typeof(List <Product>), addSaleResponse.Products);
                    operationStatusInfo.AttachedObject = collection;
                    operationStatusInfo.AttachedInfo = "Sale is added!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
예제 #2
0
        public void AddSaleUseCaseEqualTest()
        {
            price = count * product.SalesPrice;
            AddSaleRequest addSaleRequest = new AddSaleRequest(product, count.ToString(), date.ToString(), price.ToString(), seller);

            IRepositoryFactory repositoryFactory = new RepositoryFactory(new DBContext());
            IActivityFactory   activityFactory   = new ActivityFactory(repositoryFactory, new ValidationRuleFactory());
            IUseCaseFactory    useCaseFactory    = new UseCaseFactory(activityFactory);
            AddSaleResponse    addSaleResponse   = useCaseFactory.Create <IUseCase <AddSaleRequest, AddSaleResponse> >().Execute(addSaleRequest);

            Assert.AreEqual(addSaleResponse.Sales[1].Product.Id, product.Id);
            Assert.AreEqual(addSaleResponse.Sales[1].Count, count);
            Assert.AreEqual(addSaleResponse.Sales[1].Datetime.Ticks, date.Ticks);
            Assert.AreEqual(addSaleResponse.Sales[1].Price, price);
            Assert.AreEqual(addSaleResponse.Sales[1].Seller.Id, seller.Id);
        }
예제 #3
0
        public void AddSaleUseCaseNotEqualTest()
        {
            Exception exception = null;

            try
            {
                IRepositoryFactory repositoryFactory = new RepositoryFactory(new DBContext());
                IActivityFactory   activityFactory   = new ActivityFactory(repositoryFactory, new ValidationRuleFactory());
                IUseCaseFactory    useCaseFactory    = new UseCaseFactory(activityFactory);
                AddSaleRequest     addSaleRequest    = new AddSaleRequest(product, "asd", date.ToString(), price.ToString(), seller);
                AddSaleResponse    addSaleResponse   = useCaseFactory.Create <IUseCase <AddSaleRequest, AddSaleResponse> >().Execute(addSaleRequest);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.AreEqual(exception.Message, "Count must have digits only");
        }