public void Case01() { GeneralUser user = new GeneralUser { AccountName = "User03", Domain = _domain11, Name = "User03", AuthenticateWhenUnlockingScreen = true }; UserGroupEndUser userGroupEndUser = new UserGroupEndUser() { UserGroup = _userGroup1, EndUser = user }; _context.Add(user); _context.Add(userGroupEndUser); _context.SaveChanges(); var token = Utils.GetAccessToken(_client, "user1", "user1", 1, "domain11"); // ユーザー管理者 var result = Utils.Put(_client, $"{Url}/" + user.Id, null, token); var body = result.Content.ReadAsStringAsync().Result; Assert.Equal(HttpStatusCode.Forbidden, result.StatusCode); Assert.Empty(body); }
public void Case01() { var device1 = new Device { Name = "device1", ManagedNumber = "1", SerialNumber = "", ProductName = "", WindowsSignInListCacheDays = 0, Domain = _domain1, DeviceGroupDevices = new HashSet <DeviceGroupDevice> { new DeviceGroupDevice { DeviceGroup = _deviceGroup1 } }, }; _context.Add(device1); _context.SaveChanges(); var obj = new StringBuilder(); obj.AppendLine(CsvHeader); obj.AppendLine($",domain1,deviceGroup1,device3,1,1001,type01,{_lte1.Id},lte1,{_organizationClientApp1.Id},,,False,0,0001-01-01,"); obj.AppendLine($"{device1.Id},domain1,deviceGroup1,device1,1,1001,type01,{_lte1.Id},lte1,{_organizationClientApp1.Id},,,False,0,0001-01-01,"); var(response, _, json) = Utils.Post(_client, $"{Url}", Utils.CreateFormContent(obj.ToString(), "csv"), "user1", "user1", 1, "domain1"); // ユーザー管理者 Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); Assert.NotNull(json["traceId"]); Assert.NotNull(json["errors"]?["Id"]); }
public ListingMineTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); _context.Database.EnsureDeleted(); _context.Database.EnsureCreated(); _context.SaveChanges(); //_context.Organization.RemoveRange(_context.Organization); //_context.Domain.RemoveRange(_context.Domain); //_context.UserGroup.RemoveRange(_context.UserGroup); //_context.User.RemoveRange(_context.User); _context.Add(_org1 = Utils.CreateOrganization(code: 1, name: "org1")); _context.Add(_org2 = Utils.CreateOrganization(code: 2, name: "org2")); _context.Add(_domain1 = new Domain { Id = Guid.NewGuid(), Name = "domain01", Organization = _org1 }); _context.Add(_domain1A = new Domain { Id = Guid.NewGuid(), Name = "domain01a", Organization = _org1 }); _context.Add(_domain2 = new Domain { Id = Guid.NewGuid(), Name = "domain02", Organization = _org2 }); _context.Add(new SuperAdmin { AccountName = "user0", Password = Utils.HashPassword("user0") }); // スーパー管理者 _context.Add(new UserAdmin { AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1 }); // ユーザー管理者 _context.SaveChanges(); }
public ListingTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); Utils.RemoveAllEntities(_context); _context.Add(_org1 = Utils.CreateOrganization(code: 1, name: "org1")); _context.Add(_org2 = Utils.CreateOrganization(code: 2, name: "org2")); _context.Add(_domain1 = new Domain { Id = Guid.NewGuid(), Name = "domain01", Organization = _org1 }); _context.Add(_domain1a = new Domain { Id = Guid.NewGuid(), Name = "domain01a", Organization = _org1 }); _context.Add(_domain2 = new Domain { Id = Guid.NewGuid(), Name = "domain02", Organization = _org2 }); _context.Add(_user1 = new SuperAdmin { AccountName = "user0", Password = Utils.HashPassword("user0") }); // スーパー管理者 _context.Add(_user2 = new UserAdmin { AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1 }); // ユーザー管理者 _context.SaveChanges(); }
public RegisterTests(CustomWebApplicationFactoryWithMariaDb <Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); Utils.RemoveAllEntities(_context); _context.Add(_org1 = Utils.CreateOrganization(code: 1, name: "org1")); _context.Add(_domain1 = new Domain { Name = "domain1", Organization = _org1 }); _context.Add(new SuperAdmin { AccountName = "user0", Name = "", Password = Utils.HashPassword("user0") }); _context.Add(new UserAdmin { AccountName = "user1", Name = "", Password = Utils.HashPassword("user1"), Domain = _domain1 }); _context.SaveChanges(); }
public int Add(People people) { using (var context = new MainDbContext()) { context.Add <People>(people); context.SaveChanges(); return(people.Key); } }
public DeleteTests(CustomWebApplicationFactoryWithMariaDb <JinCreek.Server.Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); Utils.RemoveAllEntities(_context); _context.Add(_org1 = Utils.CreateOrganization(code: 1, name: "org1")); _context.Add(_domain1 = new Domain { Id = Guid.NewGuid(), Name = "domain01", Organization = _org1 }); _context.Add(_user1 = new SuperAdmin { AccountName = "user0", Name = "", Password = Utils.HashPassword("user0") }); // スーパー管理者 _context.Add(_user2 = new UserAdmin { AccountName = "user1", Name = "", Password = Utils.HashPassword("user1"), Domain = _domain1 }); // ユーザー管理者 _context.Add(_simGroup1 = Utils.CreateSimGroup(organization: _org1, name: "simGroup1", isolatedNw1IpPool: "isolatedNw1IpPool")); _context.SaveChanges(); }
public ListingTests(CustomWebApplicationFactoryWithMariaDb <Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); Utils.RemoveAllEntities(_context); _context.Add(new SuperAdmin { AccountName = "user0", Name = "user0", Password = Utils.HashPassword("user0") }); // スーパー管理者 _context.SaveChanges(); }
public void Case05() { _context.Add(Utils.CreateOrganization(code: 5, name: "org5")); _context.SaveChanges(); var(response, _, json) = Utils.Delete(_client, $"{Url}/5", "user0", "user0"); // スーパー管理者 Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); Assert.Null(json["traceId"]); // 不在 Assert.Null(json["errors"]); // 不在 Assert.Equal(5, json["code"]); }
public async Task MarkAsSpamAsync() { await Task.Run(() => { using (MainDbContext ctx = new MainDbContext()) { ctx.Add(new SpamMessageModel(MODEL.Message.Message.message)); } Logger.Info("Marked message as spam: " + MODEL.Message.Message.message); }); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,Skills,DateApplied,Country")] Freelancer freelancer) { if (ModelState.IsValid) { _context.Add(freelancer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Confirmation))); } return(View(freelancer)); }
public async Task <IActionResult> Create([Bind("Id,Name,Phone,VisitDate")] Patient patient) { if (ModelState.IsValid) { _context.Add(patient); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(patient)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email,Description")] Client client) { if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Confirmation))); } return(View(client)); }
public async Task <IActionResult> Create([Bind("HolidayName,DefinedDate,EncompassedYear,UpdatedBy,UpdatedDate")] Holidays holidays) { if (ModelState.IsValid) { holidays.HolidayId = Guid.NewGuid(); _context.Add(holidays); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(holidays)); }
public async Task <IActionResult> Create([Bind("BalanceId,EmployeeId,LeaveTypeId,TotalBalance,UsedBalance,RemainedBalance,IsEdited,UpdatedBy,UpdatedDate")] Balance balance) { if (ModelState.IsValid) { balance.BalanceId = Guid.NewGuid(); _context.Add(balance); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(balance)); }
public async Task <IActionResult> Create([Bind("RoleName")] Role role) { if (ModelState.IsValid) { role.RoleId = Guid.NewGuid(); _context.Add(role); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(role)); }
public AuthenticationControllerTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); // Arrange Utils.RemoveAllEntities(_context); _context.Add(new SuperAdmin { AccountName = "*****@*****.**", Password = Utils.HashPassword("9Q'vl!") }); _context.SaveChanges(); }
public async Task <IActionResult> Create([Bind("LeaveTypeId,LeaveTypeName")] LeaveType leaveType) { if (ModelState.IsValid) { leaveType.LeaveTypeId = Guid.NewGuid(); _context.Add(leaveType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(leaveType)); }
public async Task <IActionResult> Create([Bind("DepartmentName")] Department department) { if (ModelState.IsValid) { department.DepartmentId = Guid.NewGuid(); _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create([Bind("ReportId,EmployeeId,ReportingLevel,ReportTo")] Report report) { if (ModelState.IsValid) { report.ReportId = Guid.NewGuid(); _context.Add(report); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(report)); }
public void Case06() { _context.Add(new SimAndDevice() { Sim = _sim, Device = _device1, IsolatedNw2Ip = "127.0.0.1/18", AuthenticationDuration = 1, StartDate = DateTime.Parse("2020-02-01"), EndDate = DateTime.Parse("2020-02-09") }); _context.SaveChanges(); var token = Utils.GetAccessToken(_client, "user1", "user1", 1, "domain01"); // ユーザー管理者 var result = Utils.Delete(_client, $"{Url}/{_sim.Id}", token); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); var body = result.Content.ReadAsStringAsync().Result; var json = JObject.Parse(body); Assert.NotNull(json["traceId"]); // 不在 Assert.NotNull(json["errors"]?["SimAndDevice"]); }
public DeleteTests(CustomWebApplicationFactoryWithMariaDb <JinCreek.Server.Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); Utils.RemoveAllEntities(_context); _context.Add(_org1 = Utils.CreateOrganization(code: 1, name: "org1")); _context.Add(_domain1 = new Domain { Id = Guid.NewGuid(), Name = "domain01", Organization = _org1 }); _context.Add(_user1 = new SuperAdmin { Name = "", AccountName = "user0", Password = Utils.HashPassword("user0") }); // スーパー管理者 _context.Add(_user2 = new UserAdmin { Name = "", AccountName = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1 }); // ユーザー管理者 _context.Add(_simGroup1 = new SimGroup() { Id = Guid.NewGuid(), Name = "simGroup1", Organization = _org1, Apn = "apn", AuthenticationServerIp = "AuthenticationServerIp", IsolatedNw1IpPool = "IsolatedNw1IpPool", IsolatedNw1SecondaryDns = "IsolatedNw1SecondaryDns", IsolatedNw1IpRange = "IsolatedNw1IpRange", IsolatedNw1PrimaryDns = "IsolatedNw1PrimaryDns", NasIp = "NasIp", PrimaryDns = "PrimaryDns", SecondaryDns = "SecondaryDns", UserNameSuffix = "" }); _context.Add(_sim = new Sim() { SimGroup = _simGroup1, Msisdn = "1001", Imsi = "1001", IccId = "1001", UserName = "******", Password = "******" }); _context.Add(_device1 = new Device() { Domain = _domain1, Name = "device01", UseTpm = true, ManagedNumber = "001", WindowsSignInListCacheDays = 1, ProductName = "", SerialNumber = "" }); _context.SaveChanges(); }
public async void CreateNewCropRun() { ChosenIsVacant = false; var settings = SettingsService.Instance; using (var db = new MainDbContext()) { //TODO: BUG here! Does not check if the CropType already exists correctly, tries to create new one regardless var cropType = _cropTypeCache.FirstOrDefault(ct => ct.Key.Equals(UserCropType.ToLower())).Value; if (cropType == null) { cropType = new CropType { Name = UserCropType, Approved = false, CreatedAt = DateTimeOffset.Now, CreatedBy = settings.CredStableSid }; db.Add(cropType); } else { db.Attach(cropType); } var cropCycle = new CropCycle { ID = Guid.NewGuid(), Name = "Unnamed", Yield = 0, CropType = cropType, CropTypeName = cropType.Name, CropVariety = CropVariety, LocationID = _chosenPlace.Location.ID, CreatedAt = DateTimeOffset.Now, UpdatedAt = DateTimeOffset.Now, StartDate = DateTimeOffset.Now, EndDate = null, Deleted = false, Version = new byte[32] }; db.CropCycles.Add(cropCycle); await db.SaveChangesAsync(); } await BroadcasterService.Instance.TablesChanged.Invoke(string.Empty); }
public InquiryTests(CustomWebApplicationFactory <JinCreek.Server.Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); // Arrange Utils.RemoveAllEntities(_context); _context.Add(_org1 = Utils.CreateOrganization(code: 1, name: "org1")); _context.Add(_domain1 = new Domain { Id = Guid.NewGuid(), Name = "domain1", Organization = _org1 }); _context.Add(_userGroup1 = new UserGroup { Id = new Guid(), Domain = _domain1, Name = "userGroup1" }); _context.Add(_user0 = new SuperAdmin { AccountName = "user0", Password = Utils.HashPassword("user0") }); // スーパー管理者 _context.Add(_user1 = new UserAdmin // ユーザー管理者 { AccountName = "user1", Name = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1, UserGroupEndUsers = new HashSet <UserGroupEndUser> { new UserGroupEndUser { UserGroup = _userGroup1 } }, AvailablePeriods = new HashSet <AvailablePeriod> { new AvailablePeriod { StartDate = DateTime.Parse("2020-02-03"), EndDate = DateTime.Parse("2021-01-03") } } }); _context.SaveChanges(); }
public void Case04() { var multiFactor = new MultiFactor { Id = Guid.NewGuid(), SimAndDeviceId = _simDevice1.Id, EndUserId = _user1.Id, ClosedNwIp = "127.0.0.1", StartDate = DateTime.Parse("2020-02-01"), EndDate = DateTime.Parse("2020-02-07") }; _context.Add(multiFactor); _context.SaveChanges(); var(response, _, json) = Utils.Get(_client, $"{Url}/{multiFactor.Id}", "user1", "user1", 1, _domain1.Name); // ユーザー管理者 Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(multiFactor.Id, json["id"]); Assert.Equal(multiFactor.SimAndDevice.Sim.Msisdn, json["simAndDevice"]["sim"]["msisdn"]); Assert.Equal(multiFactor.SimAndDevice.Device.Name, json["simAndDevice"]["device"]["name"]); Assert.Equal(multiFactor.EndUser.AccountName, json["endUser"]["accountName"]); Assert.Equal(multiFactor.StartDate.ToString("yyyy-MM-dd"), json["startDate"]); Assert.Equal(multiFactor.EndDate?.ToString("yyyy-MM-dd"), json["endDate"]); Assert.Equal(multiFactor.ClosedNwIp, json["closedNwIp"]); }
public async Task <RentOrder> AddOrUpdate(RentOrder entity) { if (entity.RentOrderId == 0) { _dbContext.Add(entity); } else { _dbContext.RentOrders.Update(entity); } await _dbContext.SaveChangesAsync(); return(entity); }
public RegisterMineTests(CustomWebApplicationFactoryWithMariaDb <JinCreek.Server.Admin.Startup> factory) { _client = factory.CreateClient(); _context = factory.Services.GetService <IServiceScopeFactory>().CreateScope().ServiceProvider.GetService <MainDbContext>(); Utils.RemoveAllEntities(_context); _context.Add(_org1 = Utils.CreateOrganization(code: 1, name: "org1")); _context.Add(_org2 = Utils.CreateOrganization(code: 2, name: "org2")); _context.Add(_domain1 = new Domain { Id = Guid.NewGuid(), Name = "domain01", Organization = _org1 }); _context.Add(_user1 = new SuperAdmin { AccountName = "user0", Name = "user0", Password = Utils.HashPassword("user0") }); // スーパー管理者 _context.Add(_user2 = new UserAdmin { AccountName = "user1", Name = "user1", Password = Utils.HashPassword("user1"), Domain = _domain1 }); // ユーザー管理者 _context.Add(_simGroup1 = new SimGroup() { Id = Guid.NewGuid(), Name = "simGroup1", Organization = _org1, Apn = "apn", AuthenticationServerIp = "AuthenticationServerIp", IsolatedNw1IpPool = "IsolatedNw1IpPool", IsolatedNw1SecondaryDns = "IsolatedNw1SecondaryDns", IsolatedNw1IpRange = "IsolatedNw1IpRange", IsolatedNw1PrimaryDns = "IsolatedNw1PrimaryDns", NasIp = "NasIp", PrimaryDns = "PrimaryDns", SecondaryDns = "SecondaryDns", UserNameSuffix = "UserNameSuffix", }); _context.Add(_simGroup2 = new SimGroup() { Id = Guid.NewGuid(), Name = "simGroup2", Organization = _org2, Apn = "apn", AuthenticationServerIp = "AuthenticationServerIp", IsolatedNw1IpPool = "IsolatedNw1IpPool", IsolatedNw1SecondaryDns = "IsolatedNw1SecondaryDns", IsolatedNw1IpRange = "IsolatedNw1IpRange", IsolatedNw1PrimaryDns = "IsolatedNw1PrimaryDns", NasIp = "NasIp", PrimaryDns = "PrimaryDns", SecondaryDns = "SecondaryDns", UserNameSuffix = "UserNameSuffix", }); _context.SaveChanges(); }
public async Task <Book> AddOrUpdate(Book entity) { if (entity.BookId == 0) { _dbContext.Add(entity); } else { _dbContext.Books.Update(entity); } await _dbContext.SaveChangesAsync(); return(entity); }
public void AddSpamMessage(string msg) { Debug.Assert(!string.IsNullOrEmpty(msg)); using (MainDbContext ctx = new MainDbContext()) { SpamMessageModel spamMsg = ctx.SpamMessages.Where(m => m.text.Contains(msg)).FirstOrDefault(); if (spamMsg is null) { spamMsg = new SpamMessageModel(msg); } spamMsg.lastReceived = DateTime.Now; ++spamMsg.count; ctx.Add(spamMsg); } }
/// <summary> /// 添加一个挂号 /// </summary> public vwCHIS_Register AddOneRegister(int custId, int departId, int employeeId, int stationId, DateTime reservationDate, int reservationSlot, RegistFrom regFrom, out bool haveRegisted, RegisterTreatType regTreatType = RegisterTreatType.Normal, string remark = "", int?opId = null, string opMan = null, string propName = null, string propValue = null ) { if (opId == null) { opId = DbData.SystemMachineId; opMan = "SYSTEM"; } haveRegisted = false; var find = MainDbContext.CHIS_Register.FirstOrDefault(m => m.EmployeeID == employeeId && m.RegisterSlot == reservationSlot && m.CustomerID == custId && (reservationDate - m.RegisterDate.Value).Days == 0); long regid = 0; if (find == null) { var add = MainDbContext.Add(new CHIS_Register { CustomerID = custId, Department = departId, EmployeeID = employeeId, StationID = stationId, RegisterDate = reservationDate.Date, RegisterSlot = reservationSlot, RegisterTreatType = (int)regTreatType, RegisterFrom = (int)regFrom, PropName = propName, PropValue = propValue, OpID = opId, OpMan = opMan }).Entity; MainDbContext.SaveChanges(); regid = add.RegisterID; } if (find != null) { haveRegisted = true; regid = find.RegisterID; } return(MainDbContext.vwCHIS_Register.AsNoTracking().FirstOrDefault(m => m.RegisterID == regid)); }