Exemple #1
0
        public void InvalidNameErrors(string name)
        {
            Capacity capacity = new Capacity()
            {
                Id   = 1,
                Name = name
            };

            ICapacityRepository repo    = NSubstitute.Substitute.For <ICapacityRepository>();
            IJobRepository      jobRepo = NSubstitute.Substitute.For <IJobRepository>();
            CapacityRules       rules   = new CapacityRules(repo, jobRepo);

            Assert.That(() => rules.Add(capacity),
                        Throws.TypeOf <ArgumentException>().With.Message.Contains("Invalid Name"));
        }
Exemple #2
0
        public void NotDuplicateName(string name1, string name2)
        {
            Capacity capacity = new Capacity()
            {
                Id   = 1,
                Name = name1
            };

            ICapacityRepository repo    = NSubstitute.Substitute.For <ICapacityRepository>();
            IJobRepository      jobRepo = NSubstitute.Substitute.For <IJobRepository>();

            repo.Exists(Arg.Any <Capacity>()).Returns(true);
            jobRepo.Exists(Arg.Any <Job>()).Returns(true);
            CapacityRules rules = new CapacityRules(repo, jobRepo);

            Assert.That(() => rules.Add(capacity),
                        Throws.TypeOf <ArgumentException>().With.Message.Contains("Duplicated capacity"));
        }
Exemple #3
0
        public void CreateACapacityNotExistingJobError(int jobId)
        {
            Capacity capacity = new Capacity()
            {
                Id   = 1,
                Name = "TestName",
                Job  = new Job()
                {
                    Id = jobId, Name = "Tester"
                }
            };

            ICapacityRepository capacityRepo = NSubstitute.Substitute.For <ICapacityRepository>();
            IJobRepository      jobRepo      = NSubstitute.Substitute.For <IJobRepository>();

            jobRepo.Exists(Arg.Any <Job>()).Returns(false);

            CapacityRules rules = new CapacityRules(capacityRepo, jobRepo);

            Assert.That(() => rules.Add(capacity),
                        Throws.TypeOf <ArgumentException>().With.Message.Contains("The job do not exist"));
        }
Exemple #4
0
        public void CreateACapacityWithExistingJobPass(int jobId)
        {
            Capacity capacity = new Capacity()
            {
                Id   = 1,
                Name = "TestName",
                Job  = new Job()
                {
                    Id = jobId, Name = "Tester"
                }
            };

            ICapacityRepository capacityRepo = NSubstitute.Substitute.For <ICapacityRepository>();
            IJobRepository      jobRepo      = NSubstitute.Substitute.For <IJobRepository>();

            jobRepo.Exists(Arg.Any <Job>()).Returns(true);

            CapacityRules rules = new CapacityRules(capacityRepo, jobRepo);

            rules.Add(capacity);
            Assert.Pass();
        }
        bool IOptionHandle.Execute()
        {
            var capacity = new Capacity();

            Console.WriteLine("Ingrese los datos de la capacidad:");
            Console.Write("ID: ");
            string id = Console.ReadLine();

            capacity.Id = int.Parse(id);
            Console.Write("Nombre: ");
            capacity.Name = Console.ReadLine();

            Console.Write("Job ID: ");
            int jobId = int.Parse(Console.ReadLine());

            capacity.Job = new Job {
                Id = jobId
            };
            try
            {
                ICapacityRepository capacityRepository = RepositoryFactory.CreateCapacityRepository("json", GetCurrentPath());
                IJobRepository      jobRepository      = RepositoryFactory.CreateJobRepository("json", GetCurrentPath());
                var rules = new CapacityRules(capacityRepository, jobRepository);
                rules.Add(capacity);

                Console.WriteLine($"La capacidad ha sido creada correctamente. Total: {rules.Count()}");
                Console.WriteLine();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine();
                Console.Error.WriteLine($"\t{ex.Message}");
                Console.WriteLine();
                Console.WriteLine();
            }
            return(true);
        }