Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            /* Todos esse caso os dicionario Location vai criar apenas um objeto na memória, pois todos eles tem o mesmo endereço(Rua e cidade)
             * Apenas Paulo vai ser um novo registro*/
            var factory = new DeliveryFactory();

            factory.CreateDelivery(factory, "Luiz", "20A", "Av Brasil", "SP");
            factory.CreateDelivery(factory, "Helena", "300", "Av Brasil", "SP");
            factory.CreateDelivery(factory, "Joana", "512", "Av Brasil", "SP");
            factory.CreateDelivery(factory, "Paulo", "125", "Domingos Javaroni", "SP");
            var locations = factory.GetLocations();

            Console.WriteLine($"{locations.Count}");
        }
        private static DeliveryService CreateDeliveryService(DeliveryStatusEnum deliveryStatus)
        {
            var      factory  = new DeliveryFactory();
            Delivery delivery = factory.CreateDelivery();

            delivery.Status = deliveryStatus;

            bool deliveriesAreExpired = deliveryStatus != DeliveryStatusEnum.Available;

            var repository = new Mock <IRepository>();

            repository.Setup(r => r.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(delivery);
            var policy = new Mock <IExpirationPolicy>();

            policy.Setup(m => m.IsExpired(It.IsAny <Delivery>(), It.IsAny <DateTime>())).Returns(deliveriesAreExpired);

            return(new DeliveryService(repository.Object, policy.Object));
        }