public async void HRCountriesControllerOnGetAllWithValidPagingInExpectItemsAndCodeStatus200() { List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>(); for (int i = 0; i < 300; i++) { list.Add(new MongoDB.Bson.ObjectId("507f191e810c19729de860ea")); } CoreCountriesServiceStub service = new CoreCountriesServiceStub(list); HRCountriesController ctrl = new HRCountriesController(service, null); PagingParameterInModel invalidModel = new PagingParameterInModel() { PageNumber = 1, PageSize = 100 }; Task <(int, PagingParameterOutModel <HRCountry>)> resultService = ctrl.GetFromPaging(invalidModel, null); await resultService; Assert.True(resultService.Result.Item1 == StatusCodes.Status200OK); Assert.True(resultService.Result.Item2 != null); Assert.True(resultService.Result.Item2.HasNextPage); Assert.True(resultService.Result.Item2.HasPreviousPage); Assert.True(resultService.Result.Item2.TotalItemsCount == 300); int j = 100; foreach (HRCountry iterator in resultService.Result.Item2.PageItems) { j++; } Assert.True(j == 200); }
public async void HRCountriesControllerOnGetByIDWithNullServiceExpectStatus500InternalServerError() { HRCountriesController ctrl = new HRCountriesController(null, null); Task <(int, HRCountry)> resultService = ctrl.GetFromID("507f191e810c19729de860ea"); await resultService; Assert.True(resultService.Result.Item1 == StatusCodes.Status500InternalServerError); Assert.True(resultService.Result.Item2 == null); }
public async void HRCountriesControllerOnGetByIDWithIDNotBsonIDExpectStatus500InternalServerError() { List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>() { new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"), new MongoDB.Bson.ObjectId("507f191e810c19729de860eb") }; CoreCountriesServiceStub service = new CoreCountriesServiceStub(list); HRCountriesController ctrl = new HRCountriesController(service, null); Task <(int, HRCountry)> resultService = ctrl.GetFromID("507a"); await resultService; Assert.True(resultService.Result.Item1 == StatusCodes.Status500InternalServerError); Assert.True(resultService.Result.Item2 == null); }
public async void HRCountriesControllerOnGetByIDWithExistingItemExpectItemAndCodeStatus200() { List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>() { new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"), new MongoDB.Bson.ObjectId("507f191e810c19729de860eb") }; CoreCountriesServiceStub service = new CoreCountriesServiceStub(list); HRCountriesController ctrl = new HRCountriesController(service, null); Task <(int, HRCountry)> resultService = ctrl.GetFromID("507f191e810c19729de860ea"); await resultService; Assert.True(resultService.Result.Item1 == StatusCodes.Status200OK); Assert.True(resultService.Result.Item2 != null && resultService.Result.Item2._id.Equals(new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"))); }
public async void HRCountriesControllerOnGetByIDUnknownExpectStatusCode404() { List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>() { new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"), new MongoDB.Bson.ObjectId("507f191e810c19729de860eb") }; CoreCountriesServiceStub service = new CoreCountriesServiceStub(list); HRCountriesController ctrl = new HRCountriesController(service, null); Task <(int, HRCountry)> resultService = ctrl.GetFromID("507f191e810c19729de860ec"); await resultService; Assert.True(resultService.Result.Item1 == StatusCodes.Status404NotFound); Assert.True(resultService.Result.Item2 == null); }
public async void HRCountriesControllerOnGetAllWithInvalidPagingInExpectStatus416RequestedRangeNotSatisfiable() { List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>() { new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"), new MongoDB.Bson.ObjectId("507f191e810c19729de860eb") }; CoreCountriesServiceStub service = new CoreCountriesServiceStub(list); HRCountriesController ctrl = new HRCountriesController(service, null); PagingParameterInModel invalidModel = new PagingParameterInModel() { PageNumber = 2, PageSize = 100 }; Task <(int, PagingParameterOutModel <HRCountry>)> resultService = ctrl.GetFromPaging(invalidModel, null); await resultService; Assert.True(resultService.Result.Item1 == StatusCodes.Status416RequestedRangeNotSatisfiable); Assert.True(resultService.Result.Item2 == null); }
public async void HRCountriesControllerOnGetAllWithExceptionThrownByServiceExpectStatus500InternalServerError() { List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>() { new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"), new MongoDB.Bson.ObjectId("507f191e810c19729de860eb") }; CoreCountriesServiceStub service = new CoreCountriesServiceStub(list) { ThrowException = true }; HRCountriesController ctrl = new HRCountriesController(service, null); PagingParameterInModel invalidModel = new PagingParameterInModel() { PageNumber = 2, PageSize = 100 }; Task <(int, PagingParameterOutModel <HRCountry>)> resultService = ctrl.GetFromPaging(invalidModel, null); await resultService; Assert.True(resultService.Result.Item1 == StatusCodes.Status500InternalServerError); Assert.True(resultService.Result.Item2 == null); }