public void DomainService_InvalidOperationType() { TestDomainServices.EF.Northwind nw = new TestDomainServices.EF.Northwind(); DomainServiceContext dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Submit); nw.Initialize(dsc); IEnumerable <ValidationResult> validationResults = null; int totalCount; DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TestDomainServices.EF.Northwind)); DomainOperationEntry entry = dsd.DomainOperationEntries.First(p => p.Operation == DomainOperation.Query); QueryDescription qd = new QueryDescription(entry); ExceptionHelper.ExpectException <InvalidOperationException>(delegate { nw.Query(qd, out validationResults, out totalCount); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Submit, DomainOperationType.Query)); InvokeDescription id = new InvokeDescription(entry, null); ExceptionHelper.ExpectException <InvalidOperationException>(delegate { nw.Invoke(id, out validationResults); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Submit, DomainOperationType.Invoke)); nw = new TestDomainServices.EF.Northwind(); dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Query); nw.Initialize(dsc); ChangeSet cs = new ChangeSet(new ChangeSetEntry[] { new ChangeSetEntry() { Entity = new ServiceContext_CurrentOperation_Entity() { Key = 1 }, Operation = DomainOperation.Insert } }); ExceptionHelper.ExpectException <InvalidOperationException>(delegate { nw.Submit(cs); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Query, DomainOperationType.Submit)); }
public async Task DomainService_InvalidOperationType() { TestDomainServices.EF.Northwind nw = new TestDomainServices.EF.Northwind(); DomainServiceContext dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Submit); nw.Initialize(dsc); DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TestDomainServices.EF.Northwind)); DomainOperationEntry entry = dsd.GetQueryMethod(nameof(TestDomainServices.EF.Northwind.GetOrderDetails)); QueryDescription qd = new QueryDescription(entry); await ExceptionHelper.ExpectExceptionAsync <InvalidOperationException>(() => { return(nw.QueryAsync <NorthwindModel.Order_Detail>(qd, CancellationToken.None).AsTask()); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Submit, DomainOperationType.Query)); InvokeDescription id = new InvokeDescription(entry, null); await ExceptionHelper.ExpectExceptionAsync <InvalidOperationException>(() => { return(nw.InvokeAsync(id, CancellationToken.None).AsTask()); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Submit, DomainOperationType.Invoke)); nw = new TestDomainServices.EF.Northwind(); dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Query); nw.Initialize(dsc); ChangeSet cs = new ChangeSet(new ChangeSetEntry[] { new ChangeSetEntry() { Entity = new ServiceContext_CurrentOperation_Entity() { Key = 1 }, Operation = DomainOperation.Insert } }); await ExceptionHelper.ExpectExceptionAsync <InvalidOperationException>(async() => { await nw.SubmitAsync(cs, CancellationToken.None); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Query, DomainOperationType.Submit)); }
public void EFDomainService_AddUnmodifiedScenario() { // create an updated order with an attached new detail NorthwindModel.Order order = new NorthwindModel.Order { OrderID = 1, ShipCity = "London" }; NorthwindModel.Order origOrder = new NorthwindModel.Order { OrderID = 1, ShipCity = "Paris" }; NorthwindModel.Order_Detail detail = new NorthwindModel.Order_Detail { OrderID = 1, ProductID = 1 }; NorthwindModel.Order_Detail detail2 = new NorthwindModel.Order_Detail { OrderID = 1, ProductID = 2 }; order.Order_Details.Add(detail); order.Order_Details.Add(detail2); // create and initialize the service DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TestDomainServices.EF.Northwind)); TestDomainServices.EF.Northwind nw = new TestDomainServices.EF.Northwind(); DomainServiceContext dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Submit); nw.Initialize(dsc); // call attach directly - this causes the detail to be attached as unmodified order.EntityKey = nw.ObjectContext.CreateEntityKey("Orders", order); origOrder.EntityKey = nw.ObjectContext.CreateEntityKey("Orders", order); ObjectContextExtensions.AttachAsModified(nw.ObjectContext.Orders, order, origOrder); // now insert the detail, and verify that even though the detail is already // attached it can be transitioned to new nw.InsertOrderDetail(detail); nw.InsertOrderDetail(detail2); Assert.AreEqual(System.Data.Entity.EntityState.Modified, order.EntityState); Assert.AreEqual(System.Data.Entity.EntityState.Added, detail.EntityState); Assert.AreEqual(System.Data.Entity.EntityState.Added, detail2.EntityState); }
public void DomainService_InvalidOperationType() { TestDomainServices.EF.Northwind nw = new TestDomainServices.EF.Northwind(); DomainServiceContext dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Submit); nw.Initialize(dsc); IEnumerable<ValidationResult> validationResults = null; int totalCount; DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TestDomainServices.EF.Northwind)); DomainOperationEntry entry = dsd.DomainOperationEntries.First(p => p.Operation == DomainOperation.Query); QueryDescription qd = new QueryDescription(entry); ExceptionHelper.ExpectException<InvalidOperationException>(delegate { nw.Query(qd, out validationResults, out totalCount); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Submit, DomainOperationType.Query)); InvokeDescription id = new InvokeDescription(entry, null); ExceptionHelper.ExpectException<InvalidOperationException>(delegate { nw.Invoke(id, out validationResults); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Submit, DomainOperationType.Invoke)); nw = new TestDomainServices.EF.Northwind(); dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Query); nw.Initialize(dsc); ChangeSet cs = new ChangeSet(new ChangeSetEntry[] { new ChangeSetEntry() { Entity = new ServiceContext_CurrentOperation_Entity() { Key = 1 }, Operation = DomainOperation.Insert } }); ExceptionHelper.ExpectException<InvalidOperationException>(delegate { nw.Submit(cs); }, string.Format(Resource.DomainService_InvalidOperationType, DomainOperationType.Query, DomainOperationType.Submit)); }