public void CreateBranchWithAddress_Should_CreateBranchWithAddress_And_ReturnBranchDto_When_ModelStateIsValid() { // Arrange var branchCreation = new BranchWithAddressCreationDto { Branch = new BranchCreationDto { BranchCode = "002" }, Address = new AddressCreationDto { Country = "United States", City = "New York", Street = "Glenwood Ave", HouseNumber = "10", ApartmentNumber = "11", PostalCode = "10028" } }; // Act var createdAtRouteResult = _sut.CreateBranchWithAddress(branchCreation).Result as CreatedAtRouteResult; // Assert Assert.IsNotNull(createdAtRouteResult); Assert.IsInstanceOfType(createdAtRouteResult.Value, typeof(BranchDto)); var branchDto = createdAtRouteResult.Value as BranchDto; Assert.IsNotNull(branchDto); Assert.AreEqual(branchCreation.Branch.BranchCode, branchDto.BranchCode); Assert.AreEqual(branchCreation.Address.Country, branchDto.BranchAddress.Country); Assert.AreEqual(branchCreation.Address.City, branchDto.BranchAddress.City); Assert.AreEqual(branchCreation.Address.Street, branchDto.BranchAddress.Street); Assert.AreEqual(branchCreation.Address.HouseNumber, branchDto.BranchAddress.HouseNumber); Assert.AreEqual(branchCreation.Address.ApartmentNumber, branchDto.BranchAddress.ApartmentNumber); Assert.AreEqual(branchCreation.Address.PostalCode, branchDto.BranchAddress.PostalCode); var branchFromDb = _context.Branches.SingleOrDefault(b => b.Id == branchDto.Id); Assert.IsNotNull(branchFromDb); Assert.AreEqual(branchCreation.Branch.BranchCode, branchFromDb.BranchCode); Assert.AreEqual(branchCreation.Address.Country, branchFromDb.BranchAddress.Country); Assert.AreEqual(branchCreation.Address.City, branchFromDb.BranchAddress.City); Assert.AreEqual(branchCreation.Address.Street, branchFromDb.BranchAddress.Street); Assert.AreEqual(branchCreation.Address.HouseNumber, branchFromDb.BranchAddress.HouseNumber); Assert.AreEqual(branchCreation.Address.ApartmentNumber, branchFromDb.BranchAddress.ApartmentNumber); Assert.AreEqual(branchCreation.Address.PostalCode, branchFromDb.BranchAddress.PostalCode); }