コード例 #1
0
ファイル: TestContactListApi.cs プロジェクト: cx525v/WP
        public async Task ContactListApiTest_Exception()
        {
            // Arrange
            LidTypeEnum            LIDType = LidTypeEnum.CustomerNbr;
            string                 LID     = "";
            PaginationDemographics page    = new PaginationDemographics();

            string ssn = "3425";
            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);

            ILoggingFacade      loggingFacade   = Substitute.For <ILoggingFacade>();
            IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >();

            IContactListRepository mockRepo       = Substitute.For <IContactListRepository>();
            IContactListApi        contactListApi = Substitute.For <IContactListApi>();
            IDistributedCache      mockCache      = Substitute.For <IDistributedCache>();

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            mockRepo.GetContactListAsync(LIDType, LID, page).Throws(new Exception());


            contactListApi = new ContactListApi(optionsAccessor, mockRepo, loggingFacade);

            //Assert
            await Assert.ThrowsAsync <Exception>(() => contactListApi.GetContactListAsync(LIDType, LID, page));
        }
コード例 #2
0
        //Would be revisiting to modify the actual way of call method.
        public void ContactListRepositoryTest_Success()
        {
            // Arrange
            LidTypeEnum LIDType = LidTypeEnum.CustomerNbr;
            string      LID     = "";

            PaginationDemographics page = new PaginationDemographics();

            int    NameAddressID = 3301636;
            string ssn           = "3425";

            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);

            IOptions <DataContext>     optionsAccessor   = Substitute.For <IOptions <DataContext> >();
            IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>();
            IContactListRepository     mockRepo          = Substitute.For <IContactListRepository>();
            ILoggingFacade             loggingFacade     = Substitute.For <ILoggingFacade>();

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            mockRepo.GetContactListAsync(LIDType, LID, page).ReturnsForAnyArgs(expectedResult.Result);

            // Act
            var    contactList  = mockRepo.GetContactListAsync(LIDType, LID, page).Result;
            var    actualRecord = (IList <Wp.CIS.LynkSystems.Model.Demographics>)contactList.ReturnedRecords;
            string contactInfo  = actualRecord.Where(x => x.NameAddressID == NameAddressID).FirstOrDefault().Name;


            //// Assert

            Assert.Equal(((IList <Demographics>)actualRecord).Count, 3);

            Assert.Equal(contactInfo, "Golden Corral Corporation");
        }
コード例 #3
0
 public ContactListApi(IOptions <Settings> optionsAccessor,
                       IContactListRepository contactRepository,
                       ILoggingFacade loggingFacade)
 {
     _loggingFacade = loggingFacade;
     _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Contact List API Service",
                                          "ContactListApi.cs", "ContactListApi"), CancellationToken.None);
     _contactRepository = contactRepository;
 }
コード例 #4
0
        public EventsController()
        {
            try
            {
                if (!Tracker.IsActive)
                {
                    Tracker.StartTracking();
                }

                this._contactListRepository = new ContactListRepository();

                this._eventsRepository = new EventsRepository(RenderingContext.Current.Rendering.Item);
            }
            catch (Exception)
            {
                // RenderingContext does not like to be called from Javascript :< That's really a dirty things
            }
        }
コード例 #5
0
        //Mock API Call and unit test for the API call with returning mock ContactList.
        public async Task ContactListControllerTest_Success()
        {
            // Arrange

            var page = GetContactListObject();

            int                NameAddressID     = 3301636;
            string             ssn               = "3425";
            IConfigurationRoot configurationRoot = Substitute.For <IConfigurationRoot>();

            configurationRoot = GetConfiguration(configurationRoot);
            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);
            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            IDistributedCache      mockCache = Substitute.For <IDistributedCache>();
            IContactListRepository mockRepo  = Substitute.For <IContactListRepository>();
            IStringLocalizer <ContactListController> localizer
                = Substitute.For <IStringLocalizer <ContactListController> >();
            IContactListApi mockContactListApi = Substitute.For <IContactListApi>();

            IOperation fakeOperation = Substitute.For <Operation>(mockCache);

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Demographics> >())).DoNotCallBase();
            fakeOperation.WhenForAnyArgs(x => x.AddCacheAsync(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Demographics> >())).DoNotCallBase();
            ContactListController controller = new ContactListController(mockCache, mockContactListApi, localizer, fakeOperation, loggingFacade);

            mockContactListApi.GetContactListAsync(page.lidTypeEnum, page.LIDValue, page.Page).ReturnsForAnyArgs(expectedResult);
            // Act
            var contactList = await controller.GetContactList(page);

            var    actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)contactList).Value;
            string contactInfo  = ((IList <Demographics>)(((GenericPaginationResponse <Demographics>)actualRecord).ReturnedRecords)).Where(x => x.NameAddressID == NameAddressID).FirstOrDefault().Name;


            // Assert
            var recordCount = ((GenericPaginationResponse <Demographics>)actualRecord).ReturnedRecords;

            Assert.Equal(recordCount.ToList().Count, 3);

            Assert.Equal(contactInfo, "Golden Corral Corporation");
        }
コード例 #6
0
        //Unit Test for the RetrieveCache()
        public async Task ContactListControllerTest_GetDataFromCache()
        {
            var page = GetContactListObject();

            page.lidTypeEnum = LidTypeEnum.Terminal;
            page.LIDValue    = "123456";

            string                    ssn                       = "3425";
            ILoggingFacade            loggingFacade             = Substitute.For <ILoggingFacade>();
            MockContactListRepository mockContactListRepository = new MockContactListRepository();
            ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn);

            IDistributedCache      mockCache = Substitute.For <IDistributedCache>();
            IContactListRepository mockRepo  = Substitute.For <IContactListRepository>();
            IStringLocalizer <ContactListController> localizer
                = Substitute.For <IStringLocalizer <ContactListController> >();
            IContactListApi mockContactListApi = Substitute.For <IContactListApi>();

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            IOperation fakeOperation = Substitute.For <Operation>(mockCache);

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Demographics> >())).DoNotCallBase();

            fakeOperation.RetrieveCache("_123456", new GenericPaginationResponse <Demographics>()).ReturnsForAnyArgs(expectedResult.Result);
            ContactListController controller = new ContactListController(mockCache, mockContactListApi, localizer, fakeOperation, loggingFacade);


            //ACT

            var contactList = await controller.GetContactList(page);

            var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)contactList).Value;

            //Assert
            Assert.Equal(JsonConvert.SerializeObject(actualRecord), JsonConvert.SerializeObject(expectedResult.Result));
        }
コード例 #7
0
 public ContactController(IContactListRepository contactListRepository)
 {
     _contactListRepository = contactListRepository;
 }
コード例 #8
0
        public EventsController(IEventsRepository eventsRepository, IContactListRepository contactListRepository)
        {
            this._eventsRepository = eventsRepository;
            this._contactListRepository = contactListRepository;

        }
コード例 #9
0
 public InMemoryContactListService(IContactListRepository repository, IValidationRunner validationRunner)
 {
     ValidationRunner = validationRunner ?? new ValidationRunner();
     Repository = repository ?? new InMemoryContactListRepository();
 }
コード例 #10
0
 public ContactController(IContactListRepository repository)
 {
     _repository = repository;
 }
コード例 #11
0
ファイル: TestContactListApi.cs プロジェクト: cx525v/WP
 private IContactListApi FakeApi(IOptions <Settings> optionsAccessor, IContactListRepository mockRepo, ILoggingFacade loggingFacade)
 {
     return(new ContactListApi(optionsAccessor, mockRepo, loggingFacade));
 }