public async Task <PrintDrawing> GetPrintDrawingAsync(string id) { Drawing drawing; try { drawing = await _context.Drawings.AsNoTracking() .Include(d => d.Views) .ThenInclude(v => v.Structures) .ThenInclude(s => s.Fixtures) .ThenInclude(rf => rf.Fixture) .Include(d => d.Views) .ThenInclude(v => v.Structures) .ThenInclude(s => s.Fixtures) .ThenInclude(f => f.Mode) .Include(d => d.Views) .ThenInclude(v => v.Labels) .Include(d => d.Owner) .FirstAsync(d => d.Id == id); } catch (InvalidOperationException) { throw new KeyNotFoundException("Drawing ID not found"); } // only return the username, not the password hash lol drawing.Owner = new User { UserName = drawing.Owner.UserName }; PrintDrawing result = new PrintDrawing(); result.Drawing = drawing; result.UsedFixtures = new List <List <UsedFixtureResult> >(); result.RiggedFixtures = new List <RiggedFixture>(); foreach (View view in drawing.Views) { var fixtures = await _viewService.GetUsedFixturesAsync(view.Id); result.UsedFixtures.Add(fixtures.Item1); result.RiggedFixtures.AddRange(fixtures.Item2); } return(result); }
public async Task GetPrintDrawingAsync() { PrintDrawing expected = new PrintDrawing { Drawing = testDrawings[0], UsedFixtures = new List <List <UsedFixtureResult> > { new List <UsedFixtureResult> { new UsedFixtureResult { Fixture = testFixture, Count = 2 } }, new List <UsedFixtureResult> { } }, RiggedFixtures = new List <RiggedFixture>(testDrawings[0].Views[0].Structures[0].Fixtures) }; await _fixture.RunWithDatabaseAsync <PrintDrawing>( async context => { context.Users.AddRange(testUsers); context.Drawings.AddRange(testDrawings); await context.SaveChangesAsync(); }, context => initService(context).GetPrintDrawingAsync(testDrawings[0].Id), (result, context) => result.Should().BeEquivalentTo( expected, options => options.IgnoringCyclicReferences() .Excluding(d => d.SelectedMemberPath.EndsWith(".Owner")) .Excluding(d => d.SelectedMemberPath.EndsWith(".Fixture.Modes")) .Excluding(d => d.SelectedMemberPath.EndsWith(".Mode.Fixture")) .Excluding(d => d.SelectedMemberPath.Contains(".Type")) .Excluding(d => d.SelectedMemberPath.Contains(".Structure.View.")) .Excluding(d => d.Drawing.UserDrawings) ) ); }