Ejemplo n.º 1
0
        public async Task RunAsyncMethod(string since)
        {
            // preparation
            var config        = new Mock <IConfiguration>();
            var tekExportRepo = new Mock <ITemporaryExposureKeyExportRepository>();
            var resultModels  = new List <TemporaryExposureKeyExportModel>();

            for (var i = 0; i < 50; i++)
            {
                resultModels.Add(new TemporaryExposureKeyExportModel());
            }
            tekExportRepo.Setup(_ => _.GetKeysAsync(It.IsAny <ulong>()))
            .ReturnsAsync(resultModels.ToArray());
            var logger = new Mock.LoggerMock <TemporaryExposureKeysApi>();
            var temporaryExposureKeysApi = new TemporaryExposureKeysApi(config.Object, tekExportRepo.Object, logger);
            var context = new Mock.HttpContextMock();
            var q       = new Mock <IQueryCollection>();

            q.SetupGet(_ => _["since"]).Returns(since);
            context._Request.Query = q.Object;
            // action
            await temporaryExposureKeysApi.RunAsync(context.Request);

            // assert
        }
Ejemplo n.º 2
0
        public async Task RunAsyncMethod()
        {
            // preparation
            var userRepo    = new Mock <IUserRepository>();
            var cryption    = new Mock.CryptionServiceMock();
            var logger      = new Mock.LoggerMock <RegisterApi>();
            var registerApi = new RegisterApi(userRepo.Object, cryption, logger);
            var context     = new Mock.HttpContextMock();
            // action
            await registerApi.RunAsync(context.Request);

            // assert
        }
Ejemplo n.º 3
0
        public void RunMethod(int year, int month, int day)
        {
            // preparation
            var userRepo            = new Mock <IUserRepository>();
            var notification        = new Mock <INotificationService>();
            var logger              = new Mock.LoggerMock <NotificationPullApi>();
            var notificationPullApi = new NotificationPullApi(userRepo.Object, notification.Object, logger);
            var context             = new Mock.HttpContextMock();

            // action
            notificationPullApi.Run(context.Request, new DateTime(year, month, day));
            // assert
        }
Ejemplo n.º 4
0
        public async Task RunAsyncMethod(bool isValid, bool isValidDevice, string submissionNumber, string userUuid)
        {
            // preparation
            var diagnosisRepo = new Mock <IDiagnosisRepository>();

            diagnosisRepo.Setup(_ => _.SubmitDiagnosisAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TemporaryExposureKeyModel[]>()))
            .Returns(Task.CompletedTask);
            var validation       = new Mock <IValidationUserService>();
            var validationResult = new IValidationUserService.ValidateResult()
            {
                IsValid = isValid
            };

            validation.Setup(_ => _.ValidateAsync(It.IsAny <HttpRequest>(), It.IsAny <IUser>())).ReturnsAsync(validationResult);
            var deviceCheck = new Mock <IDeviceValidationService>();

            deviceCheck.Setup(_ => _.Validation(It.IsAny <DiagnosisSubmissionParameter>())).ReturnsAsync(isValidDevice);
            var logger       = new Mock.LoggerMock <Covid19Radar.Api.DiagnosisApi>();
            var diagnosisApi = new Covid19Radar.Api.DiagnosisApi(diagnosisRepo.Object, validation.Object, deviceCheck.Object, logger);
            var context      = new Mock.HttpContextMock();
            var bodyJson     = new DiagnosisSubmissionParameter()
            {
                SubmissionNumber = submissionNumber,
                UserUuid         = userUuid,
                Keys             = new DiagnosisSubmissionParameter.Key[] {
                    new DiagnosisSubmissionParameter.Key()
                    {
                        KeyData = "", RollingPeriod = 1, RollingStartNumber = 1
                    }
                }
            };
            var bodyString = Newtonsoft.Json.JsonConvert.SerializeObject(bodyJson);

            using var stream = new System.IO.MemoryStream();
            using (var writer = new System.IO.StreamWriter(stream, leaveOpen: true))
            {
                await writer.WriteAsync(bodyString);

                await writer.FlushAsync();
            }
            stream.Seek(0, System.IO.SeekOrigin.Begin);
            context._Request.Body = stream;
            // action
            await diagnosisApi.RunAsync(context.Request);

            // assert
        }
Ejemplo n.º 5
0
        public async Task RunAsyncMethodWithNull()
        {
            // preparation
            var config        = new Mock <IConfiguration>();
            var tekExportRepo = new Mock <ITemporaryExposureKeyExportRepository>();
            var resultModels  = new List <TemporaryExposureKeyExportModel>();

            tekExportRepo.Setup(_ => _.GetKeysAsync(It.IsAny <ulong>())).ReturnsAsync(resultModels.ToArray());
            var logger = new Mock.LoggerMock <TemporaryExposureKeysApi>();
            var temporaryExposureKeysApi = new TemporaryExposureKeysApi(config.Object, tekExportRepo.Object, logger);
            var context = new Mock.HttpContextMock();

            context._Request.Query = null;
            // action
            await temporaryExposureKeysApi.RunAsync(context.Request);

            // assert
        }
Ejemplo n.º 6
0
        public async Task RunAsyncMethod(bool isValid, string userUuid)
        {
            // preparation
            var notification     = new Mock.NotificationServiceMock();
            var validation       = new Mock <IValidationUserService>();
            var validationResult = new IValidationUserService.ValidateResult()
            {
                IsValid = isValid
            };

            validation.Setup(_ => _.ValidateAsync(It.IsAny <HttpRequest>(), It.IsAny <IUser>())).ReturnsAsync(validationResult);
            var logger  = new Mock.LoggerMock <UserApi>();
            var userApi = new UserApi(notification, validation.Object, logger);
            var context = new Mock.HttpContextMock();
            // action
            await userApi.RunAsync(context.Request, userUuid);

            // assert
        }
Ejemplo n.º 7
0
        public async Task RunAsyncMethod(string userUuid, bool isValid)
        {
            // preparation
            var userRepo         = new Mock <IUserRepository>();
            var diagnosisRepo    = new Mock <IDiagnosisRepository>();
            var validation       = new Mock <IValidationUserService>();
            var validationResult = new IValidationUserService.ValidateResult()
            {
                IsValid = isValid
            };

            validation.Setup(_ => _.ValidateAsync(It.IsAny <HttpRequest>(), It.IsAny <IUser>())).ReturnsAsync(validationResult);
            var logger    = new Mock.LoggerMock <OptOutApi>();
            var optOutApi = new OptOutApi(userRepo.Object, diagnosisRepo.Object, validation.Object, logger);
            var context   = new Mock.HttpContextMock();
            // action
            await optOutApi.RunAsync(context.Request, userUuid);

            // assert
        }