public async Task <ActionResult <ContactResource> > Post(ContactResource resource)
        {
            var validator        = new ContactValidator();
            var validationResult = await validator.ValidateAsync(resource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var emailValidator        = new NewContactEmailValidator(_contactsService);
            var emailValidationResult = await emailValidator.ValidateAsync(resource);

            if (!emailValidationResult.IsValid)
            {
                return(BadRequest(emailValidationResult.Errors));
            }

            var entityToCreate = _mapper.Map <ContactResource, Contact>(resource);
            var createdEntity  = await _contactsService.Create(entityToCreate);

            var createdResource = _mapper.Map <Contact, ContactResource>(createdEntity);

            return(CreatedAtAction("POST", createdResource));
        }
        public async Task <ActionResult <ContactResource> > Put(int id, ContactResource resource)
        {
            if (id != resource.Id)
            {
                return(BadRequest());
            }

            var validator        = new ContactValidator();
            var validationResult = await validator.ValidateAsync(resource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var emailValidator        = new EditContactEmailValidator(_contactsService, resource.Id);
            var emailValidationResult = await emailValidator.ValidateAsync(resource);

            if (!emailValidationResult.IsValid)
            {
                return(BadRequest(emailValidationResult.Errors));
            }

            var entityToUpdate = _mapper.Map <ContactResource, Contact>(resource);
            await _contactsService.Update(entityToUpdate);

            return(NoContent());
        }
        public ContactControllerTest()
        {
            _contactService = new ContactServiceFake();
            _controller     = new ContactController(_contactService);

            validator = new ContactValidator();
        }
        // PUT: api/ContactInformation
        public IHttpActionResult Put(Contact contact)
        {
            var validator   = new ContactValidator();
            var apiResponse = new ApiResponse();

            var results = validator.Validate(contact);

            if (!results.IsValid)
            {
                apiResponse.Errors = new Errors(results.Errors);

                return(Ok(apiResponse));
            }

            var isUpdated = ContactRepository.Update(contact);

            if (!isUpdated)
            {
                apiResponse.Errors = new Errors {
                    new Error {
                        ResponseCode = ResponseCodes.ContactNotFound
                    }
                };
            }

            return(Ok(apiResponse));
        }
 public ImporterValidatorTests()
 {
     var countryRepository = A.Fake<Domain.ICountryRepository>();
     var addressValidator = new AddressValidator(countryRepository);
     var contactValidator = new ContactValidator();
     validator = new ImporterValidator(addressValidator, contactValidator);
 }
        public IActionResult AddOrEdit(ContactVWM contact)
        {
            try
            {
                if (string.IsNullOrEmpty(contact.Id))
                {
                    ContactValidator validator = new ContactValidator(_contactService);
                    validator.InsertValidator(contact);
                    Contact newContact = PrepareNewContact(contact);
                    _contactService.Insert(newContact);
                }
                else
                {
                    ContactValidator validator = new ContactValidator(_contactService);
                    validator.UpdateValidator(contact);
                    var dataBaseEntity = _contactService.GetContact(contact.Id);
                    PrepareUpdateContact(contact, dataBaseEntity);
                    _contactService.Update(dataBaseEntity);
                }

                return(Json(true));
            }
            catch (Exception erro)
            {
                return(Json(new ValidateMessage {
                    Message = erro.Message, IsError = true
                }));
            }
        }
        public async void ContactValidatorReturnsCorrectResult(IContact model, bool expectedResult)
        {
            var sut    = new ContactValidator();
            var result = await sut.IsValidAsync(model);

            result.Should().Be(expectedResult);
        }
 public void Correct_Contact_Passes_Validation()
 {
     // Act
     bool result = new ContactValidator().Validate(_contact).IsValid;
     
     // Verify
     Assert.IsTrue(result, "Contact was incorrectly marked as invalid");
 }
 public UpdateContactController(ContactValidator validator,
                                Func <IUpdateContactSession> createSession,
                                ILogger <UpdateContactController> logger)
 {
     Validator     = validator;
     CreateSession = createSession;
     Logger        = logger;
 }
        public void Correct_Contact_Passes_Validation()
        {
            // Act
            bool result = new ContactValidator().Validate(_contact).IsValid;

            // Verify
            Assert.IsTrue(result, "Contact was incorrectly marked as invalid");
        }
Example #11
0
        public ExporterValidatorTests()
        {
            var countryRepository = A.Fake <Domain.ICountryRepository>();
            var addressValidator  = new AddressValidator(countryRepository);
            var contactValidator  = new ContactValidator();

            validator = new ExporterValidator(addressValidator, contactValidator);
        }
Example #12
0
 public static ContactValidator GetContactValidatorInstance()
 {
     if (contactValidator == null)
     {
         contactValidator = new ContactValidator(GetUnitOfWofkInstance());
     }
     return(contactValidator);
 }
        public UpdateContactControllerTests(ITestOutputHelper output) : base("api/contacts/update")
        {
            var loggerFactory = output.CreateLoggerFactory();
            var validator     = new ContactValidator(new CountryNameValidatorStub(), loggerFactory.CreateLogger <ContactValidator>());

            Session        = new UpdateContactSessionMock();
            SessionFactory = new FactorySpy <UpdateContactSessionMock>(Session);
            Controller     = new UpdateContactController(validator, SessionFactory.GetInstance, loggerFactory.CreateLogger <UpdateContactController>());
        }
        public AddContactViewModel(INavigation navigation)
        {
            _navigation        = navigation;
            _contactValidator  = new ContactValidator();
            _contact           = new ContactInfo();
            _contactRepository = new ContactRepository();

            AddContactCommand = new Command(async() => await AddContact());
        }
        public void IsValidPhoneNumber_IsBlank_GetExceptionBack()
        {
            //Arrange
            var contactValidator = new ContactValidator();
            //Act
            string PhoneNumber = "";

            //Assert
            contactValidator.IsValidPhoneNumber(PhoneNumber);
        }
 public ContactController(IContactService contactService,
                          ContactValidator contactValidator,
                          UpdateContactValidator updateContactValidator,
                          DeleteContactValidator deleteContactValidator)
 {
     _contactService         = contactService;
     _contactValidator       = contactValidator;
     _updateContactValidator = updateContactValidator;
     _deleteContactValidator = deleteContactValidator;
 }
        public void Validate_Admin_Delete_Completes(string role)
        {
            var ctx = Creator.GetContext(role: role);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var validator = new ContactValidator(_context.Object);

            var valres = validator.Validate(new Contact(), ruleSet: nameof(IContactLogic.Delete));

            valres.Errors.Should().BeEmpty();
        }
        public void Contact_With_Null_Name_Is_Invalid()
        {
            // Setup
            _contact.Name = null;

            // Act
            bool result = new ContactValidator().Validate(_contact).IsValid;

            // Verify
            Assert.IsFalse(result, "Contact was incorrectly marked as valid");
        }
        public void IsValidPhoneNumber_IsValidNegCaseLetters_GetExceptionBack()
        {
            //Arrange
            var contactValidator = new ContactValidator();
            //Act
            string PhoneNumber = "abcdwf";

            contactValidator.IsValidPhoneNumber(PhoneNumber);
            //Assert
            //Assert.IsTrue(actual);
        }
Example #20
0
        public void ValidationPhoneTest()
        {
            Contact contact = GetContactModel();

            contact.Email = "12121121tt";
            var validator = new ContactValidator();

            var result = validator.Validate(contact);

            Assert.Equals(result.Errors.First().ErrorCode.Equals(ResponseCodes.InvalidFirstName), true);
        }
        public void IsValidPhoneNumber_IsValidNegative_GetExceptionBack()
        {
            //Arrange
            var contactValidator = new ContactValidator();
            //Act
            string PhoneNumber = "033----)4(567896";

            contactValidator.IsValidPhoneNumber(PhoneNumber);
            //Assert
            //Assert.IsTrue(actual);
        }
        public void Contact_With_Null_Name_Is_Invalid()
        {
            // Setup
            _contact.Name = null;

            // Act
            bool result = new ContactValidator().Validate(_contact).IsValid;

            // Verify
            Assert.IsFalse(result, "Contact was incorrectly marked as valid");
        }
        public void Validate_NonAdmin_Update_Returns_Error(string role)
        {
            var ctx = Creator.GetContext(role: role);

            _context.Setup(c => c.HttpContext).Returns(ctx);
            var validator = new ContactValidator(_context.Object);

            var valres = validator.Validate(new Contact(), ruleSet: nameof(IContactLogic.Update));

            valres.Errors.Count().Should().Be(1);
        }
        public void IsValidPhoneNumber_IsValidPositive7_GetTrueBack()
        {
            //Arrange
            var contactValidator = new ContactValidator();
            //Act
            string PhoneNumber = "18005551234";

            bool actual = contactValidator.IsValidPhoneNumber(PhoneNumber);

            //Assert
            Assert.IsTrue(actual);
        }
Example #25
0
        public DetailsContactViewModel(INavigation navigation, int selectedContactID)
        {
            System.Diagnostics.Debug.WriteLine("==================================");
            System.Diagnostics.Debug.Flush();
            DateTime date = DateTime.Now;
            var      test = date.ToString("yyyy-MM-dd H:mm:ss.fffffffzzz");

            System.Diagnostics.Debug.WriteLine("DetailsContactViewModel() constructor -1- start - timestamp: " + test);
            System.Diagnostics.Debug.Flush();

            _navigation       = navigation;
            _contactValidator = new ContactValidator();
            _contact          = new ContactInfo();
            _contact.Id       = selectedContactID;

            GetDBConnection dbConnection = new GetDBConnection();

            if (dbConnection == null || dbConnection.Connection == null)
            {
                string errMsg = dbConnection.ConnException.Message;
                App.DatabaseError("DetailsContactViewModel() constructor", errMsg);
                return;
            }
            else
            {
                string textPointer = "pointer is null";
                if (dbConnection.Connection != null)
                {
                    if (dbConnection.Connection.Handle == null)
                    {
                        textPointer = "handle is null";
                    }
                    else
                    {
                        textPointer = dbConnection.Connection.Handle.ptr.ToString();
                    }
                }

                System.Diagnostics.Debug.WriteLine("DetailsContactViewModel() constructor -2- sqlite connection: " + textPointer);
            }

            _repository = new Repository(dbConnection.Connection);

            UpdateContactCommand = new Command(async() => await UpdateContact());
            DeleteContactCommand = new Command(async() => await DeleteContact());

            FetchContactDetails();

            test = date.ToString("yyyy-MM-dd H:mm:ss.fffffffzzz");
            System.Diagnostics.Debug.WriteLine("DetailsContactViewModel() constructor -3- end - timestamp: " + test);
            System.Diagnostics.Debug.WriteLine("==================================");
            System.Diagnostics.Debug.Flush();
        }
        public void IsValidPhoneNumber_IsValidPositive10_GetTrueBack()
        {
            //Arrange
            var contactValidator = new ContactValidator();
            //Act
            string PhoneNumber = "918880344456";

            bool actual = contactValidator.IsValidPhoneNumber(PhoneNumber);

            //Assert
            Assert.IsTrue(actual);
        }
        public DetailsViewModel(INavigation navigation, int selectedContactID)
        {
            _navigation        = navigation;
            _contactValidator  = new ContactValidator();
            _contact           = new ContactInfo();
            _contact.Id        = selectedContactID;
            _contactRepository = new ContactRepository();

            UpdateContactCommand = new Command(async() => await UpdateContact());
            DeleteContactCommand = new Command(async() => await DeleteContact());

            FetchContactDetails();
        }
Example #28
0
        public void NotCorrectPhoneShort()
        {
            ContactDTO NotValidContactDTO4 = new ContactDTO
            {
                Name         = "Jan",
                Surname      = "Novak",
                Address      = "",
                BirthNumber  = 7054251237,
                PhoneNumbers = new int?[] { 6 }
            };

            Assert.IsFalse(ContactValidator.ValidateContact(NotValidContactDTO4, 5));
        }
Example #29
0
        public void CorrectEmptyValues()
        {
            ContactDTO ValidContactDTO2 = new ContactDTO
            {
                Name         = "",
                Surname      = "Novak",
                Address      = "Doma na dvorku 35",
                BirthNumber  = 7054251237,
                PhoneNumbers = new int?[] { }
            };

            Assert.IsTrue(ContactValidator.ValidateContact(ValidContactDTO2, 5));
        }
Example #30
0
        public void CorrectAllButSurnameEmpty()
        {
            ContactDTO ValidContactDTO3 = new ContactDTO
            {
                Name         = "",
                Surname      = "Novak",
                Address      = "",
                BirthNumber  = null,
                PhoneNumbers = new int?[] { }
            };

            Assert.IsTrue(ContactValidator.ValidateContact(ValidContactDTO3, 5));
        }
Example #31
0
        public void NotCorrectSurnameMissing()
        {
            ContactDTO NotValidContactDTO1 = new ContactDTO
            {
                Name         = "Jan",
                Surname      = "",
                Address      = "",
                BirthNumber  = 7054251237,
                PhoneNumbers = new int?[] { 222222222 }
            };

            Assert.IsFalse(ContactValidator.ValidateContact(NotValidContactDTO1, 5));
        }
Example #32
0
        public void NotCorrectBirthNumberMod()
        {
            ContactDTO NotValidContactDTO2 = new ContactDTO
            {
                Name         = "Jan",
                Surname      = "Novak",
                Address      = "",
                BirthNumber  = 7054251236, //mod 11 = 10 (not 0)
                PhoneNumbers = new int?[] { 222222222 }
            };

            Assert.IsFalse(ContactValidator.ValidateContact(NotValidContactDTO2, 5));
        }
Example #33
0
        public void NotCorrectBirthNumberShort()
        {
            ContactDTO NotValidContactDTO3 = new ContactDTO
            {
                Name         = "Jan",
                Surname      = "Novak",
                Address      = "",
                BirthNumber  = 11,
                PhoneNumbers = new int?[] { 222222222 }
            };

            Assert.IsFalse(ContactValidator.ValidateContact(NotValidContactDTO3, 5));
        }
 public ContactValidatorTests()
 {
     validator = new ContactValidator();
 }