public async Task Handle_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = this.CreatePlaceOrderCommandHandler();

            var unitId = new UnitDepartmentId(1);

            var yarnCodes = new YarnCodes(new List <string> {
                "sdfsdf", "sdfds"
            });

            //var construction = new GoodsComposition(identity: Guid.NewGuid(), materialIds: new MaterialIds(new List<MaterialId>()));
            var compositionId = new GoodsCompositionId(Guid.NewGuid().ToString());

            var blended = new Blended(new List <float> {
                10.5f, 20.23f
            });

            var machineId = new MachineId(1);

            this.mockOrderRepo.Setup(x => x.Update(It.IsAny <ManufactureOrder>())).Returns(Task.FromResult(It.IsAny <ManufactureOrder>()));

            PlaceOrderCommand request = new PlaceOrderCommand
            {
                OrderDate          = DateTime.Now,
                UnitDepartmentId   = unitId,
                YarnCodes          = yarnCodes,
                GoodsCompositionId = compositionId,
                Blended            = blended,
                MachineId          = machineId,
                UserId             = "Test"
            };

            CancellationToken cancellationToken = CancellationToken.None;

            // Act
            var result = await unitUnderTest.Handle(
                request,
                cancellationToken);

            // Assert
            result.Should().NotBeNull();
        }
예제 #2
0
        public ManufactureOrder(Guid id, DateTimeOffset orderDate, UnitDepartmentId unitId, YarnCodes yarnCodes, GoodsCompositionId compositionId, Blended blended, MachineId machineId, string userId) : base(id)
        {
            // Validate Mandatory Properties
            Validator.ThrowIfNull(() => unitId);
            Validator.ThrowIfNull(() => machineId);
            Validator.ThrowIfNullOrEmpty(() => yarnCodes);
            Validator.ThrowIfNullOrEmpty(() => blended);
            Validator.ThrowIfNullOrEmpty(() => userId);

            this.MarkTransient();

            // Set initial value
            Identity         = id;
            OrderDate        = orderDate;
            UnitDepartmentId = unitId;
            YarnCodes        = yarnCodes;
            CompositionId    = compositionId;
            Blended          = blended;
            MachineId        = machineId;
            UserId           = userId;
            State            = Status.Draft;

            ReadModel = new ManufactureOrderReadModel(Identity)
            {
                MachineId        = this.MachineId.Value,
                UnitDepartmentId = this.UnitDepartmentId.Value,
                YarnCodesJson    = this.YarnCodes.Serialize(),
                State            = this.State,
                OrderDate        = this.OrderDate,
                BlendedJson      = this.Blended.Serialize(),
                UserId           = this.UserId,
            };

            if (this.CompositionId != null)
            {
                ReadModel.CompositionId = Guid.Parse(CompositionId.Value);
            }

            ReadModel.AddDomainEvent(new OnManufactureOrderPlaced(this.Identity));
        }