Esempio n. 1
0
        public void UpdateRequestStatus()
        {
            var mockDataAccess = Utilities.GetMockDataAccess();
            var requestData    = Utilities.GetRequestData(mockDataAccess.Object);
            var requestList    = requestData.GetWikiJobRequests();
            var request        = requestList.First();

            request.Status = JobStatus.PreApproved;
            requestData.UpdateStatus(request.ID, request.Status);
            mockDataAccess.Verify(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdateWikiJobRequestStatus", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, Utilities.GetUpdateStatusParams())), "JobDb"), Times.Exactly(1));
        }
Esempio n. 2
0
        public void SaveRequest()
        {
            var mockDataAccess = Utilities.GetMockDataAccess();
            var requestData    = Utilities.GetRequestData(mockDataAccess.Object);
            var request        = BuildRequest();

            var r = new DynamicParameters();

            r.Add("@Comment", request.Comment, System.Data.DbType.String);
            r.Add("@JobType", request.JobType, System.Data.DbType.String);
            r.Add("@RawRequest", request.RawRequest, System.Data.DbType.String);
            r.Add("@Status", request.Status, System.Data.DbType.Int32);
            r.Add("@SubmittedDate", request.SubmittedDateUTC, System.Data.DbType.DateTime2);
            r.Add("@Username", request.RequestingUsername, System.Data.DbType.String);
            r.Add("@ID", request.ID, System.Data.DbType.Int64, System.Data.ParameterDirection.Output);

            r.RemoveUnused = true;

            requestData.SaveWikiJobRequest(request);
            mockDataAccess.Verify(dataAccess => dataAccess.SaveData <dynamic>("dbo.spCreateUpdateWikiJobRequest", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, r)), "JobDb"), Times.Exactly(1));
        }
Esempio n. 3
0
        public void UpdateRequestTimeFinished()
        {
            var mockDataAccess = Utilities.GetMockDataAccess();
            var requestData    = Utilities.GetRequestData(mockDataAccess.Object);
            var requestList    = requestData.GetWikiJobRequests();
            var request        = requestList.First();
            var now            = DateTime.UtcNow;

            requestData.UpdateTimeFinished(request.ID, now);
            mockDataAccess.Verify(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdateWikiJobRequestTimeFinished", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, Utilities.GetTimeFinishParams(now))), "JobDb"), Times.Exactly(1));
        }
Esempio n. 4
0
        public void UpdatePages()
        {
            var         mockDataAccess = Utilities.GetMockDataAccess();
            var         requestData    = Utilities.GetRequestData(mockDataAccess.Object);
            var         requestList    = requestData.GetWikiJobRequests();
            var         request        = requestList.First();
            List <Page> pages          = new List <Page>();

            pages.Add(new Page(0, "NewPage"));
            var pageData = new PageData(mockDataAccess.Object);

            pageData.UpdatePagesForWikiJobRequest(pages, request.ID);
            mockDataAccess.Verify(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdatePagesForWikiJobRequest", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, Utilities.GetUpdatePageParams(pages, request.ID))), "JobDb"), Times.Exactly(1));
        }
Esempio n. 5
0
        public static Mock <IDataAccess> GetMockDataAccess()
        {
            var mock    = new Mock <IDataAccess>();
            var request = GetSampleJobRequest();

            request.ID = 2;

            var ldcParams = new
            {
                RequestID = request.ID
            };

            var ldParams = new
            {
                PageNumber    = 1,
                PageSize      = 10,
                SortDirection = "ASC",
                SortColumn    = "ID"
            };

            var sdParams = new DynamicParameters();

            sdParams.Add("@Comment", request.Comment, System.Data.DbType.String);
            sdParams.Add("@JobType", request.JobType, System.Data.DbType.String);
            sdParams.Add("@RawRequest", request.RawRequest, System.Data.DbType.String);
            sdParams.Add("@Status", request.Status, System.Data.DbType.Int32);
            sdParams.Add("@SubmittedDate", request.SubmittedDateUTC, System.Data.DbType.DateTime2);
            sdParams.Add("@Username", request.RequestingUsername, System.Data.DbType.String);
            sdParams.Add("@ID", request.ID, System.Data.DbType.Int64, System.Data.ParameterDirection.Output);

            sdParams.RemoveUnused = true;

            var updateStatus = GetUpdateStatusParams();

            var updateTimePreStart = GetTimePreStartParams(DateTime.UtcNow);

            var updateTimeStart = GetTimeStartParams(DateTime.UtcNow);

            var updateTimePreFinish = GetTimePreFinishParams(DateTime.UtcNow);

            var updateTimeFinish = GetTimeFinishParams(DateTime.UtcNow);

            var pages = new List <DataAccess.Objects.Page>();

            pages.Add(new DataAccess.Objects.Page(0, "NewPage"));
            var updatePages = GetUpdatePageParams(pages, request.ID);


            Type[] types = new Type[] { typeof(WikiJobRequest), typeof(DataAccess.Objects.Page) };

            var approvalRequests = GetSampleJobRequests(true).Where(x => x.Status == JobStatus.PendingPreApproval || x.Status == JobStatus.PendingApproval).ToList();

            //Instruct the mock
            mock.Setup(dataAccess => dataAccess.LoadDataComplex <WikiJobRequest, DataAccess.Objects.Page, dynamic>("dbo.spGetWikiJobRequestById", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, ldcParams)), "JobDb", types, It.IsAny <Func <WikiJobRequest, DataAccess.Objects.Page, WikiJobRequest> >(), "PageId")).Returns(GetSampleJobRequests(true).Where(request => request.ID == ldcParams.RequestID).ToList());
            mock.Setup(dataAccess => dataAccess.LoadData <WikiJobRequest, dynamic>("dbo.spGetWikiJobRequests", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, ldParams)), "JobDb")).Returns(GetSampleJobRequests(false));
            mock.Setup(dataAccess => dataAccess.LoadDataComplex <WikiJobRequest, DataAccess.Objects.Page, dynamic>("dbo.spGetWikiJobRequests", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, ldParams)), "JobDb", types, It.IsAny <Func <WikiJobRequest, DataAccess.Objects.Page, WikiJobRequest> >(), "PageId")).Returns(GetSampleJobRequests(true));
            mock.Setup(dataAccess => dataAccess.LoadDataComplex <WikiJobRequest, DataAccess.Objects.Page, dynamic>("dbo.spGetWikiJobRequestsForApproval", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, ldParams)), "JobDb", types, It.IsAny <Func <WikiJobRequest, DataAccess.Objects.Page, WikiJobRequest> >(), "PageId")).Returns(GetSampleJobRequests(true).Where(x => x.Status == JobStatus.PendingPreApproval || x.Status == JobStatus.PendingApproval).ToList());
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spCreateWikiJobRequest", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, sdParams)), "JobDb"));
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdateWikiJobRequestStatus", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, updateStatus)), "JobDb"));
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdateWikiJobRequestTimePreStarted", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, updateTimePreStart)), "JobDb"));
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdateWikiJobRequestTimeStarted", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, updateTimeStart)), "JobDb"));
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdateWikiJobRequestTimePreFinished", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, updateTimePreFinish)), "JobDb"));
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdateWikiJobRequestTimeFinished", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, updateTimeFinish)), "JobDb"));
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spCreatePages", It.IsAny <List <DataAccess.Objects.Page> >(), "JobDb"));
            mock.Setup(dataAccess => dataAccess.SaveData <dynamic>("dbo.spUpdatePagesForWikiJobRequest", It.Is <object>(y => VerifyHelper.AreEqualObjects(y, updatePages)), "JobDb"));
            var result = mock.Object.LoadDataComplex <WikiJobRequest, DataAccess.Objects.Page, dynamic>("dbo.spGetWikiJobRequestById", ldcParams, "JobDb", types, MapPageToWikiJobRequest, "PageID");

            mock.Verify(dataAccess => dataAccess.LoadDataComplex <WikiJobRequest, DataAccess.Objects.Page, dynamic>("dbo.spGetWikiJobRequestById", ldcParams, "JobDb", types, MapPageToWikiJobRequest, "PageID"));

            return(mock);
        }