public async Task RegisterNewPatientShouldReturnOK() { ContainerBuilder autoFacBuilder = new ContainerBuilder(); autoFacBuilder.Register(c => { var iPatientManager = Substitute.For<PatientManager>(); iPatientManager.RegisterNewOrUpdateDetailsAsync(Arg.Any<Patient>()).Returns<int>(1); return iPatientManager; }).InstancePerDependency(); autoFacBuilder.RegisterType<PatientManager>().As<PatientManager>().InstancePerDependency(); IContainer iContainer = autoFacBuilder.Build(); PatientController controller = new PatientController(iContainer.Resolve<IPatientManager>()); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); IHttpActionResult actionResult = await controller.PostAsync(new Patient()); var contentResult = actionResult as OkNegotiatedContentResult<string>; Assert.NotNull(contentResult); Assert.Equal("New user registration succeded", contentResult.Content); }
public async Task GetPatientDetailsShouldReturnOKWithPatient() { ContainerBuilder autoFacBuilder = new ContainerBuilder(); autoFacBuilder.Register(c => { var iPatientManager = Substitute.For<PatientManager>(); iPatientManager.FindAsync(Arg.Any<string>()).Returns<Patient>(new Patient { RegisteredUserId = 123 }); return iPatientManager; }).InstancePerDependency(); autoFacBuilder.RegisterType<PatientManager>().As<PatientManager>().InstancePerDependency(); IContainer iContainer = autoFacBuilder.Build(); PatientController controller = new PatientController(iContainer.Resolve<IPatientManager>()); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); IHttpActionResult actionResult = await controller.GetAsync("*****@*****.**"); var contentResult = actionResult as OkNegotiatedContentResult<Patient>; Assert.NotNull(contentResult); Assert.Equal(123, contentResult.Content.RegisteredUserId); }