private void ShouldAddCommunicationWithSpecifiedDBStatusCode(DBStatusCode dBStatusCode, Common.Constants.ResultType expectedResultType)
        {
            // Sample communication to test
            Communication comm = new Communication()
            {
                Text              = "Test communication",
                Subject           = "Testing communication",
                EffectiveDateTime = new DateTime(2020, 04, 04),
                ExpiryDateTime    = new DateTime(2020, 05, 13)
            };

            // Set up delegate
            DBResult <Communication> insertResult = new DBResult <Communication>
            {
                Payload = comm,
                Status  = dBStatusCode
            };

            Mock <ICommunicationDelegate> communicationDelegateMock = new Mock <ICommunicationDelegate>();

            communicationDelegateMock.Setup(s => s.Add(It.Is <Communication>(x => x.Text == comm.Text), true)).Returns(insertResult);

            // Set up service
            ICommunicationService service = new CommunicationService(
                new Mock <ILogger <CommunicationService> >().Object,
                communicationDelegateMock.Object
                );

            RequestResult <Communication> actualResult = service.Add(comm);

            // Check result
            Assert.Equal(expectedResultType, actualResult.ResultStatus);
            Assert.True(actualResult.ResourcePayload.IsDeepEqual(comm));
        }
        private void ShouldGetCommunicationsWithSpecifiedDBStatusCode(DBStatusCode dBStatusCode, Common.Constants.ResultType expectedResultType)
        {
            // Sample communication to test
            List <Communication> commsList = new List <Communication>();

            commsList.Add(new Communication()
            {
                Text              = "Test communication",
                Subject           = "Testing communication",
                EffectiveDateTime = new DateTime(2020, 04, 04),
                ExpiryDateTime    = new DateTime(2020, 05, 13)
            });

            commsList.Add(new Communication()
            {
                Text              = "Test communication 2",
                Subject           = "Testing communication 2",
                EffectiveDateTime = new DateTime(2021, 04, 04),
                ExpiryDateTime    = new DateTime(2021, 05, 13)
            });

            List <Communication> refCommsList = commsList;

            DBResult <IEnumerable <Communication> > commsDBResult = new DBResult <IEnumerable <Communication> >
            {
                Payload = commsList,
                Status  = dBStatusCode
            };

            Mock <ICommunicationDelegate> commsDelegateMock = new Mock <ICommunicationDelegate>();

            commsDelegateMock.Setup(s => s.GetAll()).Returns(commsDBResult);

            ICommunicationService service = new CommunicationService(
                new Mock <ILogger <CommunicationService> >().Object,
                commsDelegateMock.Object
                );

            RequestResult <IEnumerable <Communication> > actualResult = service.GetAll();

            Assert.Equal(expectedResultType, actualResult.ResultStatus);
            Assert.True(actualResult.ResourcePayload.IsDeepEqual(refCommsList));
        }
        private RequestResult <Communication> DeleteCommunication(Communication comm, DBStatusCode dbStatusCode)
        {
            // Set up delegate
            DBResult <Communication> deleteResult = new DBResult <Communication>
            {
                Payload = comm,
                Status  = dbStatusCode
            };

            Mock <ICommunicationDelegate> communicationDelegateMock = new Mock <ICommunicationDelegate>();

            communicationDelegateMock.Setup(s => s.Delete(It.Is <Communication>(x => x.Text == comm.Text), true)).Returns(deleteResult);

            // Set up service
            ICommunicationService service = new CommunicationService(
                new Mock <ILogger <CommunicationService> >().Object,
                communicationDelegateMock.Object
                );

            return(service.Delete(comm));
        }
Beispiel #4
0
        private RequestResult <Communication> UpdateCommunication(Communication comm, DBStatusCode dbStatusCode)
        {
            // Set up delegate
            DBResult <HealthGateway.Database.Models.Communication> insertResult = new DBResult <HealthGateway.Database.Models.Communication>
            {
                Payload = comm.ToDbModel(),
                Status  = dbStatusCode
            };

            Mock <ICommunicationDelegate> communicationDelegateMock = new Mock <ICommunicationDelegate>();

            communicationDelegateMock.Setup(s => s.Update(It.Is <HealthGateway.Database.Models.Communication>(x => x.Text == comm.Text), true)).Returns(insertResult);

            // Set up service
            ICommunicationService service = new CommunicationService(
                new Mock <ILogger <CommunicationService> >().Object,
                communicationDelegateMock.Object
                );

            return(service.Update(comm));
        }