Ejemplo n.º 1
0
        public void CreateMovementFactory(MovementType movementType, Type objectTypeOfMovement)
        {
            var movementFactory = new MovementFactory();
            var movement        = movementFactory.Create(movementType);

            Assert.AreEqual(movement.GetType(), objectTypeOfMovement);
        }
Ejemplo n.º 2
0
        public async Task NewMovementExceedsShipmentLimit_Throws()
        {
            CreateShipmentInfo(1);

            var existingMovement = new TestableMovement
            {
                Id             = new Guid("1584B5F6-4E33-441D-A9C9-17C1C3B28BA2"),
                NotificationId = NotificationId,
            };

            A.CallTo(() => movementRepository.GetAllMovements(NotificationId)).Returns(new[] { existingMovement });

            await Assert.ThrowsAsync <InvalidOperationException>(() => factory.Create(NotificationId, Today));
        }
Ejemplo n.º 3
0
        public void CreateMovementFactoryWithUndefinedMovementType()
        {
            var movementFactory = new MovementFactory();


            Assert.Throws <ArgumentNullException>(() =>
            {
                var movement = movementFactory.Create(MovementType.Unknown);
            });
        }
Ejemplo n.º 4
0
        public static Item Create(string type, Vector2 position)
        {
            switch (type)
            {
            case "seismic":
                return(new SeismicCharge(SpriteLoader.LoadSprite("sesmic_charge"), MovementFactory.Create("Stationary", 0, new List <Vector2>()
                {
                    position
                })));

            default:
                throw new NotImplementedException("other types of items are not supported");
            }
        }
Ejemplo n.º 5
0
        public async Task <Guid[]> HandleAsync(CreateMovements message)
        {
            var newIds = new List <Guid>();

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    for (int i = 0; i < message.NumberToCreate; i++)
                    {
                        var movement = await movementFactory.Create(message.NotificationId, message.ActualMovementDate);

                        context.Movements.Add(movement);

                        await context.SaveChangesAsync();

                        var shipmentQuantity = new ShipmentQuantity(message.Quantity, message.Units);
                        var packagingInfos   = await GetPackagingInfos(message.NotificationId, message.PackagingTypes);

                        var movementDetails = await movementDetailsFactory.Create(
                            movement,
                            shipmentQuantity,
                            packagingInfos);

                        context.MovementDetails.Add(movementDetails);

                        await context.SaveChangesAsync();

                        newIds.Add(movement.Id);

                        await movementAuditRepository.Add(new MovementAudit(movement.NotificationId, movement.Number,
                                                                            userContext.UserId.ToString(), (int)MovementAuditType.Incomplete, SystemTime.Now));

                        await context.SaveChangesAsync();
                    }
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }

                transaction.Commit();
            }

            return(newIds.ToArray());
        }
Ejemplo n.º 6
0
        public async Task <RoverInvoker> ExecuteMovement(string movementValue)
        {
            if (!canBeMove(movementValue))
            {
                throw new MarsRoverException("Please check rover movement type. You can use only LRM movement.", MarsRoverExceptionCode.ExecuteMovementError);
            }

            MovementFactory movementFactory = new MovementFactory();

            foreach (var c in movementValue)
            {
                MovementType movementType = (MovementType)char.ToUpper(c);
                var          move         = movementFactory.Create(movementType);
                move.Run(this._rover);
            }

            return(this);
        }
Ejemplo n.º 7
0
        public async Task <bool> HandleAsync(CreateBulkPrenotification message)
        {
            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    var draftMovements = await draftMovementRepository.GetDraftMovementById(message.DraftBulkUploadId);

                    var notification = await notificationRepository.GetById(message.NotificationId);

                    foreach (var draftMovement in draftMovements)
                    {
                        var movement = movementFactory.Create(message.NotificationId, draftMovement.ShipmentNumber,
                                                              draftMovement.Date.Value);

                        context.Movements.Add(movement);

                        await context.SaveChangesAsync();

                        await SaveMovementDetails(movement, draftMovement, notification);

                        await
                        SaveSupportingDocument(movement, draftMovement, message.FileExtension,
                                               message.SupportingDocument);

                        await SavePrenotifiedAudit(movement);
                    }

                    await draftMovementRepository.DeleteDraftMovementByNotificationId(message.NotificationId);
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
                transaction.Commit();
            }

            return(true);
        }
        public void Update(GameTime gameTime)
        {
            GameScore score = GameScore.Instance;
            uint      diff  = score.Score - lastScore;

            if (diff > 1000)
            {
                lastScore = score.Score;
                Random        rand     = new Random();
                Vector2       position = new Vector2(rand.Next(1, 1500), rand.Next(1, 1080));
                SeismicCharge charge   = new SeismicCharge(SpriteLoader.LoadSprite("sesmic_charge"), MovementFactory.Create("Stationary", 0, new List <Vector2>()
                {
                    position
                }));
                ItemsManager.Instance.Add(charge);
            }

            foreach (SeismicCharge charge in this.deployedBombs)
            {
                if (charge.IsAlive)
                {
                    charge.Update(gameTime);
                }
            }
            this.deployedBombs.RemoveAll(s => !s.IsAlive); // clean up
        }