public void GetAllContacts_UnitTestSuccess()
        {
            var mockRepository       = new Mock <IRepository>();
            var mockLoggerRepository = new Mock <ILogger>();

            mockRepository.Setup(p => p.GetAllContacts(It.IsAny <ContactSearchViewModel>())).Returns(() => new AllContactsViewModel()
            {
                PageIndex = 1, TotalItems = 10, Items = new List <UserContact>()
                {
                    new UserContact()
                    {
                        Id          = 1, FirstName = "Minh", LastName = "Nguyen",
                        Email       = "ntm1406@gmailcom", Gender = "Male", Phone = "8177736020",
                        City        = "Fort Worth", State = "Texas", Zip = "76110", UserId = 1,
                        UserProfile = new UserProfile {
                            Id = 1, Username = "******", Password = "******", FirstName = "John", LastName = "Smith", Email = "*****@*****.**"
                        }
                    }
                }
            });

            ContactDomain contactDomain = new ContactDomain(mockRepository.Object, mockLoggerRepository.Object);

            var response = contactDomain.GetAllContacts(null);

            Assert.IsNotNull(response);

            Assert.AreEqual(1, response.PageIndex);
            Assert.AreEqual(10, response.TotalItems);
            Assert.IsNotNull(response.Items);
            Assert.AreEqual("Minh", response.Items.FirstOrDefault().FirstName);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var path = args.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x));

            System.Console.WriteLine($"Processing file {path}");
            if (File.Exists(path))
            {
                using (var context = new AppDataContext(path))
                {
                    var contactDomain = new ContactDomain();
                    var addressDomain = new AddressDomain();
                    IEnumerable <KeyValuePair <int, string> > contacts = contactDomain.GetSortedListByNamesAndFrequency(context);
                    IEnumerable <string> addresses = addressDomain.SortByStreetAndFrequency(context);

                    System.Console.WriteLine($"{contacts.Count()} Names extracted");
                    System.Console.WriteLine($"{addresses.Count()} Addresses extracted");
                    System.Console.WriteLine($"Exporting to {Path.GetDirectoryName(path)}");

                    contactDomain.ExportToFile(contacts, Path.Combine(Path.GetFullPath(path), "contacts.txt"));
                    addressDomain.ExportToFile(addresses, Path.Combine(Path.GetFullPath(path), "addresses.txt"));
                    System.Console.WriteLine($"Exporting done, press any key");
                    System.Console.ReadKey();
                }
            }
        }
        public void GetUserContactId_UnitTestSuccess()
        {
            var mockRepository       = new Mock <IRepository>();
            var mockLoggerRepository = new Mock <ILogger>();

            mockRepository.Setup(p => p.GetUserContact(It.IsAny <int>())).Returns(() => new UserContact()
            {
                Id          = 1, FirstName = "Minh", LastName = "Nguyen",
                Email       = "ntm1406@gmailcom", Gender = "Male", Phone = "8177736020",
                City        = "Fort Worth", State = "Texas", Zip = "76110", UserId = 1,
                UserProfile = new UserProfile {
                    Id = 1, Username = "******", Password = "******", FirstName = "John", LastName = "Smith", Email = "*****@*****.**"
                }
            });

            ContactDomain contactDomain = new ContactDomain(mockRepository.Object, mockLoggerRepository.Object);

            var response = contactDomain.GetUserContact(1);

            Assert.IsNotNull(response);

            Assert.AreEqual(1, response.Id);
            Assert.AreEqual("Minh", response.FirstName);
            Assert.AreEqual("8177736020", response.Phone);
            Assert.AreEqual("jsmith", response.UserProfile.Username);
            Assert.IsNotNull(response.UserProfile.Password);
            Assert.IsNull(response.UserProfile.CreateBy);
        }
예제 #4
0
        public void GetContacts_UnitTestSuccess()
        {
            var mockRepository = new Mock <IRepository>();

            mockRepository.Setup(r => r.GetAllContacts(It.IsAny <ContactFilterViewModel>())).Returns(() => new ContactViewModel()
            {
                PageIndex = 1, TotalItems = 10, Items = new List <UsermanagementApp.Entity.UserContact>()
                {
                    new UsermanagementApp.Entity.UserContact()
                    {
                        Id = 1, FirstName = "satya", LastName = "pala"
                    }
                }
            });

            ContactDomain contactDomain = new ContactDomain(mockRepository.Object);

            var response = contactDomain.GetAllContacts(null);

            Assert.IsNotNull(response);

            Assert.AreEqual(1, response.PageIndex);
            Assert.AreEqual(10, response.TotalItems);
            Assert.IsNotNull(response.Items);
            Assert.AreEqual("satya", response.Items.FirstOrDefault().FirstName);
        }
예제 #5
0
        public async Task <IActionResult> Edit(int contactId, ContactDomain contact)
        {
            if (contact == null)
            {
                _logger.LogError("contact object sent from client is null.");
                return(BadRequest("contact object is null"));
            }

            if (!ModelState.IsValid)
            {
                _logger.LogError("Invalid contact object sent from client.");
                return(BadRequest("Invalid model object"));
            }

            var dbContact = await _contactService.GetContactById(contactId);

            if (dbContact == null)
            {
                _logger.LogError($"Contact with id: {contactId}, hasn't been found in db.");
                return(NotFound());
            }

            var result = await _contactService.EditContact(contact);

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
예제 #6
0
        public async Task <bool> ContactExists(ContactDomain contact)
        {
            var contactExists = await _repositoryWrapper.contact.GetContact(x => x.FirstName == contact.FirstName &&
                                                                            x.LastName == contact.LastName &&
                                                                            x.PhoneNumber == contact.PhoneNumber);

            if (contactExists.Id > 0)
            {
                return(true);
            }
            return(false);
        }
예제 #7
0
        public void TestGetSortedListByNamesAndFrequency()
        {
            var domain  = new ContactDomain();
            var context = new Mock <AppDataContext>();

            context.SetupGet(x => x.Contacts)
            .Returns(() =>
            {
                return(new Repository <Contact>(new List <Contact>()
                {
                    new Contact {
                        FirstName = "John", LastName = "Doe"
                    },
                    new Contact {
                        FirstName = "Peter", LastName = "Botha"
                    },
                    new Contact {
                        FirstName = "Sarie", LastName = "Coetzee"
                    },
                    new Contact {
                        FirstName = "Gerrit", LastName = "de Bruin"
                    },
                    new Contact {
                        FirstName = "Jan", LastName = "vd Merwe"
                    },
                    new Contact {
                        FirstName = "Sarel", LastName = "Doe"
                    },
                    new Contact {
                        FirstName = "Koos", LastName = "Smith"
                    },
                    new Contact {
                        FirstName = "Sannie", LastName = "Smith"
                    }
                }));
            });
            IEnumerable <KeyValuePair <int, string> > result = domain.GetSortedListByNamesAndFrequency(context.Object);

            Assert.IsNotNull(result);
            CollectionAssert.AllItemsAreUnique(result.ToList());
            Assert.IsTrue(result.Any(), "Returned No Resultes");
            Assert.IsTrue(result.Count() == 14, "Result count mismatch");
            Assert.IsTrue(result.First().Key == 2, "First element count mismatch");
            Assert.IsTrue(result.First().Value == "Doe", "First element last name mismatch");
            Assert.IsTrue(result.Last().Key == 1, "Last element count mismatch");
            Assert.IsTrue(result.Last().Value == "vd Merwe", "Last element last name mismatch");
        }
예제 #8
0
        public async Task <IActionResult> Add([FromBody] ContactDomain contact)
        {
            try
            {
                if (contact == null)
                {
                    _logger.LogError("Contact object sent from client is null.");
                    return(BadRequest("Contact object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid Contact object sent from client.");
                    return(BadRequest("Invalid model object"));
                }
                var contactExists = await _contactService.ContactExists(contact);

                if (contactExists)
                {
                    return(StatusCode(409, new { message = $"Contact with name {contact.FirstName} {contact.LastName} and phone number {contact.PhoneNumber} already exists." }));
                }

                var result = await _contactService.AddContact(contact);

                if (result)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #9
0
 public FaleConoscoController(ContactDomain domain)
 {
     _domain = domain;
 }
예제 #10
0
        public async Task <bool> EditContact(ContactDomain contact)
        {
            var _contact = _mapper.Map <Contact>(contact);

            return(await _repositoryWrapper.contact.EditContact(_contact));
        }
예제 #11
0
 public HomeController(ContactDomain contactDomain)
 {
     _contactDomain = contactDomain;
 }