예제 #1
0
        public Task AddOrder(ManufactureOrder order)
        {
            var readModel = _mapper.Map <ManufactureOrder, ManufactureOrderReadModel>(order);

            readModel.TransferDomainEvents(order);

            _context.ManufactureOrders.Add(readModel);

            return(Task.CompletedTask);
        }
예제 #2
0
        public ManufactureOrderDto(ManufactureOrder order)
        {
            OrderDate        = order.OrderDate;
            UnitDepartmentId = order.UnitDepartmentId;
            YarnCodes        = order.YarnCodes;
            Blended          = order.Blended;
            MachineId        = order.MachineId;
            State            = order.State;
            UserId           = order.UserId;
            Id = order.Identity;

            LastModifiedDate = order.AuditTrail.ModifiedDate ?? order.AuditTrail.CreatedDate;
            LastModifiedBy   = order.AuditTrail.ModifiedBy ?? order.AuditTrail.CreatedBy;
        }
        public async Task Get_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateOrdersController();

            //fake

            var goodsId = Guid.NewGuid();
            var product = new Goods(goodsId, "Benang 401");

            var unitId = Guid.NewGuid();

            var unit = new UnitDepartment(unitId, "Spinning");

            var flowId = Guid.NewGuid();

            var flow = new ManufactureFlow(flowId, product, new List <ManufactureOrderActivityType> {
                ManufactureOrderActivityType.Spinning_Blowing,
                ManufactureOrderActivityType.Spinning_Carding
            });

            var orderCode = "MO010101";

            var order = new ManufactureOrder(Guid.NewGuid(), orderCode, unit, flow, product);

            var orders = new List <ManufactureOrder>()
            {
                order
            };

            this.mockManufactureOrderRepo.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(orders.AsQueryable()));

            this.mockMapper.Setup(x => x.Map <ManufactureOrder, ManufactureOrderDto>(It.IsAny <ManufactureOrder>()))
            .Returns(new ManufactureOrderDto
            {
                Id   = order.Identity.ToString(),
                Code = order.Code
            });

            // Act
            var result = await unitUnderTest.Get();

            // Assert

            result.Should().BeOfType <OkObjectResult>()
            .Subject.Value.Should().BeOfType <List <ManufactureOrderDto> >()
            .Subject.Count.Should().BeGreaterThan(0);
        }
예제 #4
0
        public async Task Post_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = CreateOrdersController();

            //fake

            var goodsId = Guid.NewGuid();
            var product = new Goods(goodsId, "Benang 401");

            var unitId = Guid.NewGuid();

            var unit = new UnitDepartment(unitId, "Spinning");

            var flowId = Guid.NewGuid();

            var flow = new ManufactureFlow(flowId, product, new List <ManufactureOrderActivityType> {
                ManufactureOrderActivityType.Spinning_Blowing,
                ManufactureOrderActivityType.Spinning_Carding
            });

            var orderCode = "MO010101";

            var order = new ManufactureOrder(Guid.NewGuid(), "MO010101", unit, flow, product);

            this.mockManufactureOrderService.Setup(x => x.PlaceOrderAsync(orderCode, unitId, flowId, goodsId)).Returns(Task.FromResult(order));

            var form = new ManufactureOrderForm
            {
                Code            = orderCode,
                UnitId          = unitId.ToString(),
                FlowId          = flowId.ToString(),
                OutputProductId = goodsId.ToString()
            };

            // Act
            IActionResult result = await unitUnderTest.Post(form);

            // Assert
            result.Should().BeOfType <OkObjectResult>()
            .Subject.Value.Should().BeOfType <string>()
            .Subject.Should().Be(order.Identity.ToString());
        }
예제 #5
0
        public async Task <ManufactureOrder> PlaceOrderAsync(string orderCode, Guid unitId, Guid flowId, Guid goodsId)
        {
            var goods = new Goods(_productRepository.GetProductById(goodsId));

            var unit = new UnitDepartment(_departmentRepository.GetDepartmentById(unitId));

            var flow = new ManufactureFlow(flowId, goods, new List <ManufactureOrderActivityType> {
                ManufactureOrderActivityType.Spinning_Blowing,
                ManufactureOrderActivityType.Spinning_Carding
            });

            var orderId = Guid.NewGuid();
            var order   = new ManufactureOrder(orderId, orderCode, unit, flow, goods);

            order.AddDomainEvent(new OnManufactureOroderPlaced(orderId));

            await _manufactureOrderRepository.AddOrder(order);

            await _productRepository.UnitOfWork.SaveChangesAsync();

            return(order);
        }