public ServiceController(InternalServicesDirectoryV1Context context)
 {
     // TODO: Once all CRUD methods use '_serviceContext', remove '_context' as a data member
     // and pass 'context' directly to the 'ServiceContext' constructor
     _context        = context;
     _contextManager = new ContextManager(_context);
 }
Exemple #2
0
        public void TestGetLanguageNotFound()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    context.Language.Add(new Language());
                    context.SaveChanges();

                    LanguageController controller = new LanguageController(context);
                    var actionResult = controller.Get(2).Result;
                    var result       = actionResult as NotFoundObjectResult;

                    Assert.IsNotNull(actionResult);
                    Assert.AreEqual(404, result.StatusCode);
                    Assert.AreEqual("No languages from given id found.", result.Value);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public void TestPutDepartmentNotFound()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var department = new Department {
                        DepartmentCode = 1
                    };
                    context.Department.Add(new Department {
                        DepartmentCode = 1
                    });
                    context.Department.Add(new Department {
                        DepartmentCode = 2
                    });
                    context.Department.Add(new Department {
                        DepartmentCode = 3
                    });
                    context.SaveChanges();

                    DepartmentController controller = new DepartmentController(context);
                    department.DepartmentId   = 4;
                    department.DepartmentName = "department4";
                    department.DepartmentCode = 4;

                    var actionResult = controller.PutDepartment(department.DepartmentId, department.ToDepartmentV1DTO()).Result;
                    var result       = actionResult as NotFoundResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(404, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public void TestGetLocation()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    context.LocationType.Add(new LocationType {
                        LocationTypeName = "location1"
                    });
                    context.SaveChanges();
                    context.Location.Add(new Location {
                        LocationTypeId = 1
                    });
                    context.Location.Add(new Location {
                        LocationTypeId = 1
                    });
                    context.Location.Add(new Location {
                        LocationTypeId = 1
                    });
                    context.SaveChanges();

                    LocationController controller = new LocationController(context);
                    var actionResult = controller.Get(2).Result;
                    var result       = actionResult as OkObjectResult;
                    var location     = result.Value as LocationV1DTO;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(200, result.StatusCode);
                    Assert.IsNotNull(location);
                    Assert.AreEqual(2, location.LocationId);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #5
0
        public void TestPutDivision()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var division = new Division {
                        DivisionCode = 1
                    };
                    context.Division.Add(division);
                    context.Division.Add(new Division {
                        DivisionCode = 2
                    });
                    context.Division.Add(new Division {
                        DivisionCode = 3
                    });
                    context.SaveChanges();

                    DivisionController controller = new DivisionController(context);
                    division.DivisionId   = 1;
                    division.DivisionName = "division1";
                    division.DivisionCode = 4;

                    var actionResult = controller.PutDivision(division.DivisionId, division.ToDivisionV1DTO()).Result;
                    var result       = actionResult as NoContentResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(204, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public void TestGetDepartment()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    context.Department.Add(new Department {
                        DepartmentCode = 1
                    });
                    context.Department.Add(new Department {
                        DepartmentCode = 2
                    });
                    context.Department.Add(new Department {
                        DepartmentCode = 3
                    });
                    context.SaveChanges();

                    DepartmentController controller = new DepartmentController(context);
                    var actionResult = controller.Get(2).Result;
                    var result       = actionResult as OkObjectResult;
                    var department   = result.Value as DepartmentV1DTO;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(200, result.StatusCode);
                    Assert.IsNotNull(department);
                    Assert.AreEqual(2, department.DepartmentId);
                    Assert.AreEqual(2, department.DepartmentCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #7
0
        public void TestPutLocationTypeNotFound()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var locationType = new LocationType {
                        LocationTypeName = "locationType1"
                    };
                    context.LocationType.Add(locationType);
                    context.LocationType.Add(new LocationType {
                        LocationTypeName = "locationType2"
                    });
                    context.LocationType.Add(new LocationType {
                        LocationTypeName = "locationType3"
                    });
                    context.SaveChanges();

                    LocationTypeController controller = new LocationTypeController(context);
                    locationType.LocationTypeId   = 4;
                    locationType.LocationTypeName = "locationType4";
                    var actionResult = controller.PutLocationType(locationType.LocationTypeId, locationType.ToLocationTypeV1DTO()).Result;
                    var result       = actionResult as NotFoundResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(404, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public void TestPutProgram()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var program = new Program();
                    context.Program.Add(program);
                    context.Program.Add(new Program());
                    context.Program.Add(new Program());
                    context.SaveChanges();

                    ProgramController controller = new ProgramController(context);
                    program.ProgramId          = 1;
                    program.ProgramName        = "program1";
                    program.SponsorName        = "sponsor1";
                    program.ProgramOfferNumber = "offerNumber1";
                    program.OfferType          = "offerType1";
                    var actionResult = controller.PutProgram(program.ProgramId, program.ToProgramV1DTO()).Result;
                    var result       = actionResult as NoContentResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(204, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #9
0
        public void TestPutLanguage()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var language = new Language();
                    context.Language.Add(language);
                    context.Language.Add(new Language());
                    context.Language.Add(new Language());
                    context.SaveChanges();

                    LanguageController controller = new LanguageController(context);
                    language.LanguageId   = 1;
                    language.LanguageName = "language1";
                    var actionResult = controller.PutLanguage(language.LanguageId, language.ToLanguageV1DTO()).Result;
                    var result       = actionResult as NoContentResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(204, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #10
0
        public void TestPutCommunityNotFound()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var community = new Community();
                    context.Community.Add(community);
                    context.Community.Add(new Community());
                    context.Community.Add(new Community());
                    context.SaveChanges();

                    CommunityController controller = new CommunityController(context);
                    community.CommunityId   = 4;
                    community.CommunityName = "community4";
                    var actionResult = controller.PutCommunity(community.CommunityId, community.ToCommunityV1DTO()).Result;
                    var result       = actionResult as NotFoundResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(404, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #11
0
 public CommunityController(InternalServicesDirectoryV1Context context)
 {
     _contextManager = new ContextManager(context);
 }
Exemple #12
0
 public LocationController(InternalServicesDirectoryV1Context context)
 {
     _contextManager = new ContextManager(context);
 }
Exemple #13
0
 public ContextManager(InternalServicesDirectoryV1Context context)
 {
     _context = context;
 }
 public DepartmentController(InternalServicesDirectoryV1Context context)
 {
     _contextManager = new ContextManager(context);
 }
 public ProgramController(InternalServicesDirectoryV1Context context)
 {
     _contextManager = new ContextManager(context);
 }
 public LanguageController(InternalServicesDirectoryV1Context context)
 {
     _languageContextManager = new ContextManager(context);
 }