Esempio n. 1
0
        public void GetNameTypeCheck()
        {
            NamesController namesController = new NamesController(_context);
            var             result          = namesController.GetName("AAA", "BBB");

            Assert.IsType <ActionResult <Name> >(result);
        }
Esempio n. 2
0
        public void GetNamesTypeCheck()
        {
            NamesController namesController = new NamesController(_context);
            var             result          = namesController.GetNames();

            Assert.IsType <ActionResult <IEnumerable <Name> > >(result);
        }
 public void Test_For_Simple_hello_with_name()
 {
     {
         NamesController nc = new NamesController();
         Assert.Equal("Hi shubham", nc.Get("shubham"));
     }
 }
Esempio n. 4
0
        public void CreateNameTypeCheck()
        {
            NamesController namesController = new NamesController(_context);

            Name testName = new Name {
                Id = new Guid(), FirstName = "GGG", LastName = "HHH"
            };

            var result = namesController.CreateName(testName);

            Assert.IsType <ActionResult <Name> >(result);
        }
Esempio n. 5
0
        public void Can_Filter_Name_Type_By_Middle()
        {
            // Arrange
            Mock <INamesRepository> mock = new Mock <INamesRepository>();

            NameEntry[] namesMock = new NameEntry[]
            {
                new NameEntry {
                    Id = 1, Name = "Dax", Weight = 0.07f
                },
                new NameEntry {
                    Id = 2, Name = "Michael", Weight = 0.6f
                },
                new NameEntry {
                    Id = 3, Name = "Devon", Weight = 0.2f
                },
                new NameEntry {
                    Id = 4, Name = "Bruce", Weight = 0.15f
                },
                new NameEntry {
                    Id = 5, Name = "Desmond", Weight = 0.0f
                },
                new NameEntry {
                    Id = 6, Name = "John", Weight = 0.5f
                }
            };
            mock.Setup(m => m.Names).Returns(namesMock.AsQueryable <NameEntry>());

            NamesController controller = new NamesController(mock.Object);

            // Act
            IEnumerable <NameEntry> result = controller.GetNames("middle");

            NameEntry[] nameArray       = result.OrderBy(n => n.Id).ToArray();
            NameEntry[] namesMockMiddle = namesMock.Where(n => n.Weight >= 0.5f).ToArray();

            // Assert

            Assert.Equal(namesMockMiddle.Length, nameArray.Length);
            Assert.Equal("Michael", nameArray[0].Name);
            Assert.Equal("John", nameArray[1].Name);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            // Check input parameter
            if (args == null || args.Length == 0)
            {
               Console.WriteLine("Please provide a filepath.");
               Console.WriteLine("Press any key to exit.");
                Console.Read();
                return;
            }
            if (!args[0].TxtFileFormat())
            {
                Console.WriteLine("Please provide a valid .txt file.");
                Console.WriteLine("Press any key to exit.");
                Console.Read();
                return;
            }

            // Run the program
            try
            {
                NamesController namesController = new NamesController();
                var result = namesController.ProcessNameFile(args[0]);

                foreach (var source in result)
                {
                    Console.Write(source.LastName + ", ");
                    Console.WriteLine(source.FirstName);
                }
                Console.WriteLine("Finished: created {0}", namesController.GetOutputFileName(false));
                Console.Read();
            }
            catch (ArgumentException)
            {
                Console.WriteLine("The provided file was invalid");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something has gone wrong. Error: {0}", ex.Message);
            }
        }
Esempio n. 7
0
        public async void Can_Post_New_Name()
        {
            // Arrange
            Mock <INamesRepository> mock = new Mock <INamesRepository>();

            NameEntry[] namesMock = new NameEntry[]
            {
                new NameEntry {
                    Id = 1, Name = "Dax", Weight = 0.07f
                },
                new NameEntry {
                    Id = 2, Name = "Michael", Weight = 0.6f
                },
                new NameEntry {
                    Id = 3, Name = "Devon", Weight = 0.2f
                },
                new NameEntry {
                    Id = 4, Name = "Bruce", Weight = 0.15f
                },
                new NameEntry {
                    Id = 5, Name = "Desmond", Weight = 0.0f
                },
                new NameEntry {
                    Id = 6, Name = "John", Weight = 0.5f
                }
            };
            mock.Setup(m => m.Names).Returns(namesMock.AsQueryable <NameEntry>());

            NamesController controller = new NamesController(mock.Object);

            // Act
            NameEntry newName = new NameEntry
            {
                Id = 7, Name = "Test", Weight = 0.5f
            };

            await controller.PostNameEntry(newName);

            // Assert
            // TODO: need DB mock for this
        }
Esempio n. 8
0
        public void Can_Use_Repository()
        {
            // Arrange
            Mock <INamesRepository> mock = new Mock <INamesRepository>();

            NameEntry[] namesMock = new NameEntry[]
            {
                new NameEntry {
                    Id = 1, Name = "Dax", Weight = 0.07f
                },
                new NameEntry {
                    Id = 3, Name = "Devon", Weight = 0.2f
                },
                new NameEntry {
                    Id = 2, Name = "Michael", Weight = 0.6f
                },
                new NameEntry {
                    Id = 4, Name = "Bruce", Weight = 0.15f
                },
                new NameEntry {
                    Id = 5, Name = "Desmond", Weight = 0.0f
                },
                new NameEntry {
                    Id = 6, Name = "John", Weight = 0.5f
                }
            };
            mock.Setup(m => m.Names).Returns(namesMock.AsQueryable <NameEntry>());

            NamesController controller = new NamesController(mock.Object);

            // Act
            IEnumerable <NameEntry> result = controller.GetNames();

            // Assert
            NameEntry[] nameArray = result.ToArray();
            Assert.True(nameArray.Length == namesMock.Length);
            Assert.Equal("Dax", nameArray[0].Name);
            Assert.Equal("Devon", nameArray[1].Name);
        }
Esempio n. 9
0
 public void Setup_Controller()
 {
     fileMock = new FileAccessMock();
      nameCtrl = new NamesController(fileMock);
 }
Esempio n. 10
0
        public async Task <GetNumberOfCheckedNames> CheckAllFiles([FromUri] Guid guidUser, [FromBody] ObjectSubmit senderRecipients, [FromUri] bool tsc,
                                                                  [FromUri] bool frc, [FromUri] bool rrc, [FromUri] int userId)
        {
            SenderDto sender = new SenderDto();

            sender = senderRecipients.sender;
            List <GetRecipent> GetRecipents = senderRecipients.recipients;

            GetNumberOfCheckedNames ncn  = new GetNumberOfCheckedNames();
            List <GetCheckedNames>  lgcn = new List <GetCheckedNames>();

            //MULTIPLE USERS
            var users = _context.Users.Where(a => a.guidUser == guidUser);

            //ERRORE GUID
            if (users.Count() == 0)
            {
                ncn.numberOfValidNames = 0;
                ncn.state = "Utente non riconosiuto";
                return(ncn);
            }

            //UTENTE INSERITORE
            var u = new Users();

            if (userId > 0)
            {
                u = users.SingleOrDefault(a => a.id == userId);
            }
            else
            {
                u = users.SingleOrDefault(a => a.parentId == 0);
            }


            //ERRORE MITTENTE
            ControlloMittente ctrlM = GlobalClass.verificaMittente(senderRecipients.sender);

            if (!ctrlM.Valido)
            {
                ncn.numberOfValidNames = 0;
                ncn.state = "Mittente non valido";
                return(ncn);
            }

            OperationsController oc = new OperationsController();
            OperationsDto        op = new OperationsDto();

            op.date              = DateTime.Now;
            op.name              = " Operazione del " + DateTime.Now.ToString("dd/MM/yyyy");
            op.userId            = u.id;
            op.operationType     = (int)operationType.MOL;
            op.demoOperation     = u.demoUser;
            op.areaTestOperation = u.areaTestUser;
            op.complete          = false;
            int operationId = OperationsController.CreateItem(op);

            tipoStampa ts = tipoStampa.colori;

            if (tsc)
            {
                ts = tipoStampa.biancoNero;
            }

            fronteRetro fr = fronteRetro.fronte;

            if (frc)
            {
                fr = fronteRetro.fronteRetro;
            }

            ricevutaRitorno rr = ricevutaRitorno.si;

            if (rrc)
            {
                rr = ricevutaRitorno.no;
            }


            createFeatures(ts, fr, rr, operationId);

            SenderDtos ss = Mapper.Map <SenderDto, SenderDtos>(sender);

            ss.operationId = operationId;
            int senderId = SenderController.CreateItem(ss);

            int validNames = 0;

            foreach (var GetRecipent in GetRecipents.ToList())
            {
                int id = (int)GetRecipent.recipient.id;
                var b  = _context.Bulletins.Where(a => a.namesListsId == id).ToList();
                if (b.Count() > 0)
                {
                    GetRecipent.bulletin = Mapper.Map <Bulletins, BulletinsDtos>(b[0]);
                }
                ;

                NamesDtos nos = Mapper.Map <NamesDto, NamesDtos>(GetRecipent.recipient);
                nos.operationId = operationId;
                nos.requestId   = null;
                nos.guidUser    = null;
                nos.valid       = true;

                nos.fronteRetro     = Convert.ToBoolean(fr);
                nos.ricevutaRitorno = Convert.ToBoolean(rr);
                nos.tipoStampa      = Convert.ToBoolean(ts);

                nos.insertDate   = DateTime.Now;
                nos.currentState = (int)currentState.inAttesa;

                var nc     = new NamesController();
                int idName = nc.CreateItem(nos, u.userPriority);
                if (GetRecipent.bulletin != null)
                {
                    BulletinsDto bos = Mapper.Map <BulletinsDtos, BulletinsDto>(GetRecipent.bulletin);
                    bos.namesId = idName;
                    BulletinsController.CreateItem(bos);
                }
                validNames++;

                GetCheckedNames gcn = new GetCheckedNames()
                {
                    name  = nos,
                    valid = true,
                    price = new Prices()
                };

                lgcn.Add(gcn);
            }

            ncn.numberOfValidNames = validNames;
            ncn.checkedNames       = lgcn;
            ncn.state       = "Inserimento valido!";
            ncn.valid       = true;
            ncn.operationId = operationId;

            return(ncn);
        }