public async Task <ActionResult> InternalPublishCoursesToSearchAndCompare(string providerCode, [FromBody] BackendRequest request)
        {
            var result = await _searchAndCompareService.SaveCourses(providerCode, request.Email);

            return(Ok(new{ result }));
        }
Exemplo n.º 2
0
        public void PublishEnrichedCoursesWithEmailHappyPathTest()
        {
            var email    = "*****@*****.**";
            var provider = new Provider
            {
                ProviderCode      = ProviderCode,
                AccreditedCourses =
                    new List <Course> {
                    new Course {
                        CourseCode = CourseCode, ProgramType = "SD", Name = "History"
                    }
                }
            };

            _dataServiceMock.Setup(x => x.GetProviderForUser(email, ProviderCode)).Returns(provider);
            _dataServiceMock.Setup(x => x.GetCourseForUser(email, ProviderCode, CourseCode))
            .Returns(BuildCourse(provider));

            _dataServiceMock.Setup(x => x.GetCourseForUser(email, ProviderCode, CourseCode + "1"))
            .Returns(new Course {
                CourseCode = CourseCode + "1", Provider = provider, ProgramType = "SD", CourseSubjects = new List <CourseSubject> {
                    new CourseSubject {
                        Subject = new Subject {
                            SubjectName = "Geography"
                        }
                    }
                }, Name = "Geography"
            });

            _dataServiceMock.Setup(x => x.GetCoursesForUser(email, ProviderCode))
            .Returns(new List <Course> {
                new Course {
                    CourseCode = CourseCode, Provider = provider, ProgramType = "SD", CourseSubjects = new List <CourseSubject> {
                        new CourseSubject {
                            Subject = new Subject {
                                SubjectName = "History"
                            }
                        }
                    }, Name = "History"
                }, new Course {
                    CourseCode = CourseCode + "1", Provider = provider, ProgramType = "SD", CourseSubjects = new List <CourseSubject> {
                        new CourseSubject {
                            Subject = new Subject {
                                SubjectName = "Geography"
                            }
                        }
                    }, Name = "History"
                }
            });

            _enrichmentServiceMock.Setup(x => x.GetProviderEnrichmentForPublish(ProviderCode, email))
            .Returns(new UcasProviderEnrichmentGetModel {
                EnrichmentModel = new ProviderEnrichmentModel()
            });

            var enrichmentModel = new CourseEnrichmentModel {
                FeeDetails = "It's gonna cost you", FeeInternational = (Decimal)123.5, FeeUkEu = (Decimal)234.5
            };

            _enrichmentServiceMock.Setup(x => x.GetCourseEnrichmentForPublish(ProviderCode, CourseCode, email))
            .Returns(new UcasCourseEnrichmentGetModel {
                CourseCode = CourseCode, ProviderCode = ProviderCode, EnrichmentModel = enrichmentModel, Status = EnumStatus.Published
            });

            _enrichmentServiceMock.Setup(x => x.GetCourseEnrichmentForPublish(ProviderCode, CourseCode + "1", email))
            .Returns(new UcasCourseEnrichmentGetModel {
                CourseCode = CourseCode + "1", ProviderCode = ProviderCode, EnrichmentModel = enrichmentModel, Status = EnumStatus.Published
            });

            _httpMock.Setup(x => x.PutAsync(It.Is <Uri>(y => y.AbsoluteUri == $"{sncUrl}/courses"), It.IsAny <StringContent>())).ReturnsAsync(
                new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            }
                ).Verifiable();

            var result = _searchAndCompareService.SaveCourses(ProviderCode, email).Result;

            result.Should().BeTrue();
            _httpMock.VerifyAll();
        }