Inheritance: ApiController
        public async Task<HttpResponseMessage> GetInventoryReportPDF()
        {
            try
            {
                string fileName = string.Concat("InventoryReport.pdf");
                string filePath = HttpContext.Current.Server.MapPath("~/Reports/" + fileName);

                ContactController contact = new ContactController();
                ContactContext ContactsDB = new ContactContext();
                List<Contact> contactList = new List<Contact>();
                contactList = ContactsDB.Contacts;

                await NowManagementStudio.Report.ReportGenerator.GeneratePDF(contactList, filePath);

                HttpResponseMessage result = null;
                result = Request.CreateResponse(HttpStatusCode.OK);
                result.Content = new StreamContent(new FileStream(filePath, FileMode.Open));
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                result.Content.Headers.ContentDisposition.FileName = fileName;
                return result;
            }
            catch (Exception ex)
            {
                log.Error("Error Generating Contact Report PDF : " + ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
        }
示例#2
0
 public ActionResult Recapcha(ContactController.ContactModel model)
 {
     if (Valid() )
     {
         return RedirectToAction("ThankYou", "Public");
     }
     else
     {
         return View(model);
     }
 }
示例#3
0
        public void AddEmail_ShouldWork()
        {
            var controller = new ContactController();

            controller.Clear();
            Contact contact = new Contact();

            contact.Name1    = "Ilze";
            contact.Surname1 = "Berzina";
            ContactService _contactService = new ContactService();

            controller.AddContact(contact);

            Emails email = new Emails();

            email.EmailAddress = "*****@*****.**";
            email.Type         = "home";
            email.ContactId    = contact.Id;
            _contactService.AddEmailService(email);
            controller.AddEmail(email);
            Assert.IsTrue(_contactService.ExistsEmail(email));
        }
示例#4
0
        //private CountryController               CntrlCY;


        public ClientForm()
        {
            InitializeComponent(); if (DesignMode || (Site != null && Site.DesignMode))
            {
                return;
            }
            //template
            Mapper["Id"]        = txtId;
            Mapper["CreatedBy"] = txtCreatedBy;
            Mapper["CreatedOn"] = txtCreatedOn;
            Mapper["UpdatedBy"] = txtUpdatedBy;
            Mapper["UpdatedOn"] = txtUpdatedOn;
            Mapper["ReadOnly"]  = chkReadOnly;
            //data
            Mapper["ClientTypeId"]   = txtClientTypeId;
            Mapper["ShortName"]      = txtShortName;
            Mapper["LongName"]       = txtLongName;
            Mapper["NameArabic"]     = txtNameArabic;
            Mapper["DateOfBirth"]    = txtDateOfBirth;
            Mapper["IsActive"]       = chkIsActive;
            Mapper["BillingAddress"] = txtBillingAddress;
            Mapper["PhoneNumber"]    = txtPhoneNumber;
            Mapper["FaxNumber"]      = txtFaxNumber;
            Mapper["Website"]        = txtWebsite;
            Mapper["CountryId"]      = txtCountryId;
            //actions
            SaveButton   = btnSave;
            DeleteButton = btnDelete;
            NewButton    = btnNew;
            //pick lists
            PickList[btnPLCountry]         = txtCountryId;
            PickList[btnPLClientType]      = txtClientTypeId;
            PickList[btnPLClientShortName] = txtId;

            CntrlCO = DBControllersFactory.Contact();
            CntrlCI = DBControllersFactory.ClientIdentification();
            CntrlID = DBControllersFactory.Identification();
            CntrlCC = DBControllersFactory.ClientContact();
        }
        public void PutTest()
        {
            // Arrange
            ContactController controller = new ContactController();

            Contact contactToUpdate = new Contact()
            {
                FirstName   = "Vince",
                LastName    = "Chao",
                Email       = "*****@*****.**",
                PhoneNumber = 9878954321,
                Status      = true
            };

            // Act
            IHttpActionResult actionResult = controller.Put(contactToUpdate);
            var contentResult = actionResult as OkNegotiatedContentResult <Contact>;

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Contact>));
            Assert.AreEqual(contentResult.Content, contactToUpdate);
        }
示例#6
0
        public void GetContact_should_return_Ok_with_responsebody_when_get_return_data_records()
        {
            // Arrange
            ContactDTO dto = new ContactDTO()
            {
                ID = 1
            };
            var mockRepository = new Mock <IRepository <ContactDTO> >();

            mockRepository.Setup(item => item.Get(It.IsAny <int>())).Returns(dto);
            var controller = new ContactController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.GetContact(1);
            var contentResult = actionResult as OkNegotiatedContentResult <ContactDTO>;

            // Assert

            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(1, contentResult.Content.ID);
        }
示例#7
0
        public void GetContacts_ShouldReturnContactsWithSameID()
        {
            //Arrange
            var mockRepository = new Mock <IContactServices>();

            var ContactEntity = new ContactEntity();

            ContactEntity = new ContactEntity {
                ContactID = 3, FirstName = "test5", LastName = "test5", EmailAddress = "*****@*****.**", PhoneNumber = "222-111-3333", IsActive = true
            };


            mockRepository
            .Setup(x => x.GetContactById(3))
            .Returns(ContactEntity);

            var controller = new ContactController(mockRepository.Object);
            var result     = controller.GetContact(3) as OkNegotiatedContentResult <ContactEntity>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.ContactID);
        }
示例#8
0
        public void UpdateContact_ShouldWork()
        {
            var controller = new ContactController();

            controller.Clear();
            Contact contact = new Contact();

            contact.Name1    = "Ilze";
            contact.Surname1 = "Berzina";
            contact.Company  = "MyComnapy";
            ContactService _contactService = new ContactService();

            controller.AddContact(contact);
            Assert.IsTrue(_contactService.Exists(contact));

            Assert.IsTrue(contact.Name2 == null);

            contact.Name2 = "Updating Name2";

            controller.UpdateContact(contact.Id, contact);
            Assert.IsTrue(contact.Name2 == "Updating Name2");
        }
        public async void Controller_GetAction_ShouldReturn_ActionResult_IEnumerableContact()
        {
            //Arrange
            var expected = new List <Contact>
            {
                new Contact {
                    Id = Guid.NewGuid(), Name = "Brenton Bates", EmailAddress = "*****@*****.**"
                },
                new Contact {
                    Id = Guid.NewGuid(), Name = "Sean Livingston", EmailAddress = "*****@*****.**"
                },
                new Contact {
                    Id = Guid.NewGuid(), Name = "Stephon Johnson", EmailAddress = "*****@*****.**"
                }
            };

            var mockContactService = new Mock <IContactService>(MockBehavior.Default);
            var mockLoggerService  = new Mock <ILogger <ContactController> >(MockBehavior.Default);

            mockContactService
            .Setup(x => x.Get())
            .ReturnsAsync(expected);

            var controller = new ContactController(mockLoggerService.Object, mockContactService.Object);

            //Act
            var actionResult = await controller.Get();

            var okObjectResult = actionResult.Result as OkObjectResult;

            //Assert
            Assert.NotNull(actionResult);
            Assert.NotNull(okObjectResult);
            Assert.True(typeof(ActionResult <IEnumerable <Contact> >).IsAssignableFrom(actionResult.GetType()));
            var actual = Assert.IsAssignableFrom <IEnumerable <Contact> >(okObjectResult.Value);

            expected.Should().BeEquivalentTo(actual);
        }
示例#10
0
        public async Task Delete_Ok()
        {
            //Arrange
            var validContactId = 1;
            var contactIds     = new List <int>()
            {
                validContactId
            };

            //Act
            var controller = new ContactController(_serviceBusMock.Object, _contactContext.Object);

            controller.ControllerContext = FakeControllerContext();

            var actionResult = await controller.Delete(contactIds);

            _serviceBusMock.Verify(mock => mock.Publish(It.IsAny <ContactsDeletedIntegrationEvent>()), Times.Once);

            //Assert
            var result = Assert.IsType <OkResult>(actionResult);

            Assert.Equal((int)System.Net.HttpStatusCode.OK, result.StatusCode);
        }
        public void post()
        {
            // Arrange

            Mock <IContact> mockContactRepo = new Mock <IContact>();
            var             item            = new Contact();

            item.FirstName = "A";
            item.LastName  = "B";
            item.Email     = "*****@*****.**";
            item.Id        = 5;
            item.Status    = "Active";
            mockContactRepo.Setup(m => m.AddContact(item)).Returns(item);
            ContactController controller = new ContactController(mockContactRepo.Object);

            controller.Request       = new System.Net.Http.HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();
            // Act
            var result = controller.Post(item);

            // Assert
            Assert.IsTrue(result.IsSuccessStatusCode);
        }
示例#12
0
        public void Setup()
        {
            // Arrange
            var mockMailHandler        = new Mock <IMailHandler>();
            var messagesAreaOfInterest = new Mock <DbSet <MessagesAreaOfInterest> >();
            var mockDb = new Mock <ContactDbContext>();

            mockDb.Setup(p => p.MessagesAreaOfInterest).Returns(messagesAreaOfInterest.Object);

            var mailOptions = Options.Create(new MailHandler());

            mailOptions.Value.ReceiverEmailAddress  = "test";
            mailOptions.Value.ReceiverDisplayName   = "test";
            mailOptions.Value.ReceiverEmailPassword = "******";
            mailOptions.Value.Port = "";
            mailOptions.Value.Host = "";

            mockMailHandler.Setup(t => t.Configure("test", "test", "test", "", ""));
            mockMailHandler.Setup(t => t.SendEmail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(),
                                                   null, It.IsAny <string>(), It.IsAny <string>())).Returns(Task.Delay(0));

            _controller = new ContactController(mockMailHandler.Object, mockDb.Object, mailOptions);
        }
示例#13
0
        public void GetContacts_should_return_Ok_with_responsebody_when_getall_return_data_records()
        {
            // Arrange
            IEnumerable <ContactDTO> lstcon = new List <ContactDTO>()
            {
                new ContactDTO()
                {
                    ID = 1
                }
            };
            var mockRepository = new Mock <IRepository <ContactDTO> >();

            mockRepository.Setup(item => item.GetAll()).Returns(lstcon);
            var controller = new ContactController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.GetContacts();
            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <ContactDTO> >;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
        }
示例#14
0
        public void DeleteContactsTest()
        {
            var mockContext = new Mock <ContactsContext>();

            var mockSet = MockSet(GetEvolventContactsMock());

            try
            {
                //Setting up the mockSet to mockContext
                mockContext.Setup(c => c.Contact).Returns(mockSet.Object);

                var repository = new ContactRepository(mockContext.Object);
                var controller = new ContactController(repository);

                var result = controller.DeleteContact(1);

                Assert.IsTrue(result);
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }
示例#15
0
        public void Get_Edit_Not_Ajax_Request()
        {
            // Arrange
            var xmlManager = Substitute.For <IXmlManager>();
            var mapper     = Substitute.For <IMapper>();

            var fakeController = new FakeController();

            fakeController.PrepareFakeRequest();
            var controller = new ContactController(xmlManager, mapper);

            controller.ControllerContext = fakeController.GetControllerContext <ContactController>(new RouteData(), controller);

            // Act
            var result      = controller.Edit() as RedirectToRouteResult;;
            var ajaxRequest = controller.Request.IsAjaxRequest();
            var actionName  = result.RouteValues.Values.ElementAt(0);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsFalse(ajaxRequest);
            Assert.That("Index", Is.EqualTo(actionName));
        }
示例#16
0
        public void GetAllInActiveContactsTest()
        {
            var mockContext = new Mock <ContactsContext>();

            var mockSet = MockSet(GetEvolventContactsMock());

            try
            {
                //Setting up the mockSet to mockContext
                mockContext.Setup(c => c.Contact).Returns(mockSet.Object);

                var repository = new ContactRepository(mockContext.Object);
                var controller = new ContactController(repository);

                var result = controller.GetAllInActiveContacts();

                Assert.AreEqual(0, result.Count());
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }
        public void GetById()
        {
            // Arrange
            Mock <IContact> mockContactRepo = new Mock <IContact>();
            var             item            = new Contact();

            item.FirstName = "A";
            item.LastName  = "B";
            item.Email     = "*****@*****.**";
            item.Id        = 1456;
            item.Status    = "Active";
            mockContactRepo.Setup(m => m.GetContact(item.Id)).Returns(item);
            ContactController controller = new ContactController(mockContactRepo.Object);

            controller.Request       = new System.Net.Http.HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            // Act
            var result = controller.GetContactById(1456);

            // Assert
            Assert.IsNotNull(result);
        }
示例#18
0
        public void GetAllContactsTest()
        {
            var contactController = new ContactController(_contactService)
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri(ServiceBaseURL + "v1/Contacts/Contact/all")
                }
            };

            contactController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
            _response = contactController.Get();
            var responseResult = JsonConvert.DeserializeObject <List <Contact> >(_response.Content.ReadAsStringAsync().Result);

            Assert.AreEqual(_response.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual(responseResult.Any(), true);
            var comparer = new ContactComparer();

            CollectionAssert.AreEqual(
                responseResult.OrderBy(contact => contact, comparer),
                _contacts.OrderBy(contact => contact, comparer), comparer);
        }
示例#19
0
        public void Contact_EditTest()
        {
            Mock <IContactRepository> mock = new Mock <IContactRepository>();

            mock.Setup(m => m.Contacts).Returns(new List <Contact>()
            {
                new Contact {
                    ContactId = 1, Name = "11", Surname = "11"
                },
                new Contact {
                    ContactId = 2, Name = "22", Surname = "22"
                },
                new Contact {
                    ContactId = 3, Name = "33", Surname = "33"
                }
            });

            ContactController target = new ContactController(mock.Object);

            var result = (ViewResult)target.EditContact(1).ViewData.Model;

            Assert.AreEqual((result as Contact).ContactId, mock.Object.Contacts)
        }
        public void TestPutContact()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var contact = new Contact();
                    context.Contact.Add(contact);
                    context.Contact.Add(new Contact());
                    context.Contact.Add(new Contact());
                    context.SaveChanges();

                    ContactController controller = new ContactController(context);
                    contact.ContactId   = 1;
                    contact.ContactName = "contact1";
                    var actionResult = controller.PutContact(contact.ContactId, contact.ToContactV1DTO()).Result;
                    var result       = actionResult as NoContentResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(204, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public void Generate_Function_Specified_Contact_Count()
        {
            //arrange
            Mock <IContactRepository> mock = new Mock <IContactRepository>();

            mock.Setup(m => m.Contacts).Returns(new Contact[]
            {
                new Contact {
                    ContactId = 1, LastName = "1", City = "Минск", Function = "директор"
                },
                new Contact {
                    ContactId = 2, LastName = "2", City = "Минск", Function = "бухгалтер"
                },
                new Contact {
                    ContactId = 3, LastName = "3", City = "Москва", Function = "директор"
                },
                new Contact {
                    ContactId = 4, LastName = "4", City = "Москва", Function = "бухгалтер"
                },
                new Contact {
                    ContactId = 5, LastName = "5", City = "Саратов", Function = "уборщик"
                }
            }.AsQueryable());
            ContactController controller = new ContactController(mock.Object);

            //act
            int res1   = ((ContactListViewModel)controller.List(null, "директор").Model).PagingInfo.TotalItems;
            int res2   = ((ContactListViewModel)controller.List(null, "бухгалтер").Model).PagingInfo.TotalItems;
            int res3   = ((ContactListViewModel)controller.List(null, "уборщик").Model).PagingInfo.TotalItems;
            int resAll = ((ContactListViewModel)controller.List().Model).PagingInfo.TotalItems;

            //assert
            Assert.AreEqual(res1, 2);
            Assert.AreEqual(res2, 2);
            Assert.AreEqual(res3, 1);
            Assert.AreEqual(resAll, 5);
        }
示例#22
0
        public void Edit()
        {
            ContactController obj = new ContactController();

            obj.BaseAddress = ContactApiBaseAddress;

            //Get the latest contact to edit...
            var itemToEdit = GetAllContactsFromRepository().OrderByDescending(x => x.Id).FirstOrDefault();

            itemToEdit.firstName   = "edit_New_Sachin";
            itemToEdit.lastName    = "edit_New_Erande";
            itemToEdit.phoneNumber = "+91-90823677222";
            itemToEdit.email       = "*****@*****.**";
            itemToEdit.status      = status.InActive;

            var vr = obj.Edit(itemToEdit.Id, itemToEdit);

            if (!(vr is RedirectToRouteResult))
            {
                Assert.Fail("Edit Failed.");
            }
            Assert.IsNotNull(vr);

            //Get the edited contact from repository..
            var EditedItem = GetAllContactsFromRepository().Where(x => x.Id == itemToEdit.Id).FirstOrDefault();

            Assert.IsNotNull(EditedItem);

            //check all the properties were updated successfully.
            Assert.AreEqual(EditedItem.Id, itemToEdit.Id);
            Assert.AreEqual(EditedItem.firstName, itemToEdit.firstName);
            Assert.AreEqual(EditedItem.lastName, itemToEdit.lastName);
            Assert.AreEqual(EditedItem.phoneNumber, itemToEdit.phoneNumber);
            Assert.AreEqual(EditedItem.email, itemToEdit.email);
            Assert.AreEqual(EditedItem.status, itemToEdit.status);
        }
示例#23
0
        public void UpdateContactTest()
        {
            var contactController = new ContactController(_contactService)
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Put,
                    RequestUri = new Uri(ServiceBaseURL + "v1/Contacts/Contact/Modify")
                }
            };

            contactController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var firstContact = _contacts.First();

            firstContact.FirstName = "Contact updated";
            var updatedContact = new ContactEntity()
            {
                FirstName = firstContact.FirstName, ID = firstContact.ID
            };

            contactController.Put(firstContact.ID, updatedContact);
            Assert.That(firstContact.ID, Is.EqualTo(1));
        }
示例#24
0
        public async Task DeleteContact(int id)
        {
            //Arrange

            var repository = new Mock <IContactRepository>();

            repository.Setup(x => x.Delete(It.IsAny <int>())).ReturnsAsync(id);

            ContactController controller = new ContactController(repository.Object);

            controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
            };
            controller.ControllerContext.HttpContext.Request.Headers.Add(ContactManagerConstatants.ClientId, "12345");

            //Act
            var response = await controller.Delete(id);

            //Assert
            var result = ((int)((ObjectResult)response).Value);

            Assert.Equal(id, result);
        }
示例#25
0
        public async Task Update_BadRequest_ListDoesntExist()
        {
            //Arrange
            var listThatDoesntExist = 10;
            var model = new UpdateContactDTO()
            {
                Id        = 1,
                FirstName = "test",
                LastName  = "test",
                Email     = "*****@*****.**",
                Active    = true,
                ListIds   = new List <int>()
                {
                    listThatDoesntExist
                }
            };

            //Act
            var controller   = new ContactController(_serviceBusMock.Object, _contactContext.Object);
            var actionResult = await controller.Update(model);

            //Assert
            var result = Assert.IsType <BadRequestResult>(actionResult);
        }
        public void Can_Send_Pagination_View_Model()
        {
            //arrange
            Mock <IContactRepository> mock = new Mock <IContactRepository>();

            mock.Setup(m => m.Contacts).Returns(new Contact[]
            {
                new Contact {
                    ContactId = 1, LastName = "1"
                },
                new Contact {
                    ContactId = 2, LastName = "2"
                },
                new Contact {
                    ContactId = 3, LastName = "3"
                },
                new Contact {
                    ContactId = 4, LastName = "4"
                },
                new Contact {
                    ContactId = 5, LastName = "5"
                }
            }.AsQueryable());
            ContactController controller = new ContactController(mock.Object);

            //act
            ContactListViewModel result = (ContactListViewModel)controller.List(null, null, 3, 2).Model;

            //assert
            PagingInfo pagingInfo = result.PagingInfo;

            Assert.AreEqual(pagingInfo.CurrenPage, 2);
            Assert.AreEqual(pagingInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagingInfo.TotalItems, 5);
            Assert.AreEqual(pagingInfo.TotalPages, 2);
        }
示例#27
0
        public void UpdateEmail_ShouldNotWork()
        {
            var controller = new ContactController();

            controller.Clear();
            Contact contact = new Contact();

            contact.Name1    = "Ilze";
            contact.Surname1 = "Berzina";
            ContactService _contactService = new ContactService();

            controller.AddContact(contact);

            Emails email = new Emails();

            email.EmailAddress = "*****@*****.**";
            email.Type         = "home";
            email.ContactId    = contact.Id;
            _contactService.AddEmailService(email);
            controller.AddEmail(email);
            email.EmailAddress = "emailgmailcom";
            controller.UpdateEmail(email.EmailID, email);
            Assert.IsFalse(email.EmailAddress == "emailgmailcom");
        }
示例#28
0
        public void EditContactTest()
        {
            // Arrange
            var contact = new Contact {
                Id = 1, FirstName = "Evolent"
            };

            HttpResponseMessage resposnse = new HttpResponseMessage();

            resposnse.StatusCode = HttpStatusCode.Accepted;

            var mockRepo = new Mock <IWebApiCall>();

            mockRepo.Setup(x => x.Put(contact)).Returns(resposnse);

            // Arrange
            ContactController controller = new ContactController(mockRepo.Object);

            // Act
            var result = controller.EditContact(contact) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }
示例#29
0
 public ContactControllerTests()
 {
     mockMediator = new Mock <IMediator>();
     sut          = new ContactController(mockMediator.Object, new AppSettings());
 }
示例#30
0
 public ContactControllerTests(ControllerFixture controllerFixture)
 {
     sut     = new ContactController(controllerFixture.Mediator, new AppSettings());
     fixture = controllerFixture;
 }
 public UcContactForm()
 {
     InitializeComponent();
     ContactCtrl = new ContactController();
 }
 public ContactControllerTests()
 {
     _mediatorFake = A.Fake <IMediator>();
     _mapperFake   = A.Fake <IMapper>();
     _sut          = new ContactController(_mediatorFake, _mapperFake);
 }
示例#33
0
 public static ContactController Fixture()
 {
     ContactController controller = new ContactController(new ContactRepository());
     return controller;
 }