Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion Extensions/Xtensive.Orm.BulkOperations.Tests/Other.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using System;
// Copyright (C) 2012-2020 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alexander Ovchinnikov
// Created: 2012.02.29

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
Expand Down Expand Up @@ -242,5 +248,34 @@ public void In()
trx.Complete();
}
}

[Test]
public void InWithCombinationWithFieldUsageUpdate()
{
using (Session session = Domain.OpenSession())
using (TransactionScope trx = session.OpenTransaction()) {
var idsToUpdate = new[] { 99, 100, 102 };
var prefix = "abc";

var bar1 = new Bar(session, 100) { Name = "test1", Count = 3 };
var bar2 = new Bar(session, 101) { Name = "test2", Count = 4 };
var bar3 = new Bar(session, 102) { Name = "test3", Count = 5 };
session.SaveChanges();

var updatedCount = session.Query.All<Bar>()
.Where(b => b.Id.In(IncludeAlgorithm.ComplexCondition, idsToUpdate))
.Update(bar => new Bar(session) { Name = prefix + bar.Name });
Assert.That(updatedCount, Is.EqualTo(2));

var all = session.Query.All<Bar>().Where(b=> b.Id == 100 || b.Id == 101 || b.Id == 102).ToList();
var updatedEntities = all.Where(b => b.Id.In(idsToUpdate));
Assert.That(updatedEntities.All(e => e.Name.StartsWith(prefix)), Is.True);

var leftEntities = all.Where(b => !b.Id.In(idsToUpdate));
Assert.That(leftEntities.All(e => e.Name.StartsWith(prefix)), Is.False);

trx.Complete();
}
}
}
}
6 changes: 3 additions & 3 deletions Orm/Xtensive.Orm.Tests/Issues/CustomCompilerException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2011 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2011-2020 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alexis Kochetov
// Created: 2011.05.29

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2013 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2013-2020 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alexey Kulakov
// Created: 2013.07.30

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2015 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Copyright (C) 2015-2020 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alexey Kulakov
// Created: 2015.12.01

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (C) 2020 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alexey Kulakov
// Created: 2020.02.14

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Xtensive.Orm.Configuration;
using Xtensive.Orm.Validation;
using Xtensive.Orm.Tests.Issues.IssueJira0792_UnableToRemoveAssignedEntityWithNonNullableAssociationFieldModel;

namespace Xtensive.Orm.Tests.Issues.IssueJira0792_UnableToRemoveAssignedEntityWithNonNullableAssociationFieldModel
{
[HierarchyRoot]
public class Job : Entity
{
[Field, Key]
public long Id { get; private set; }

[Field]
[Association(PairTo = nameof (JobTechnology.ReqiredJob),
OnTargetRemove = OnRemoveAction.Clear,
OnOwnerRemove = OnRemoveAction.Cascade)]
public JobTechnology Technology { get; set; }

public Job(Session session)
: base(session)
{
}
}

[HierarchyRoot]
public class JobTechnology : Entity
{
[Field, Key]
public long Id { get; set; }

[Field(Nullable = false), NotNullConstraint]
public Job ReqiredJob { get; set; }

public JobTechnology(Session session, Job job)
: base(session)
{
ReqiredJob = job;
}
}
}

namespace Xtensive.Orm.Tests.Issues
{
public class IssueJira0792_UnableToRemoveAssignedEntityWithNonNullableAssociationField : AutoBuildTest
{
protected override DomainConfiguration BuildConfiguration()
{
var configuration = base.BuildConfiguration();
configuration.Types.Register(typeof(Job).Assembly, typeof(Job).Namespace);
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
return configuration;
}

protected override void PopulateData()
{
using (var session = Domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
new JobTechnology(session, new Job(session));
new JobTechnology(session, new Job(session));
new JobTechnology(session, new Job(session));
new JobTechnology(session, new Job(session));

transaction.Complete();
}
}

[Test]
public void MainTest()
{
using (var session = Domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
foreach (var job in session.Query.All<Job>()) {
job.Technology.Remove();
session.SaveChanges();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// Copyright (C) 2020 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Alexey Kulakov
// Created: 2020.02.18

using System;
using System.Collections.Generic;
using System.Text;
using Xtensive.Orm.Configuration;
using Xtensive.Orm.Validation;
using Xtensive.Orm.Tests.Issues.IssueJira0793_FieldValidationTriggersLazyLoadFieldsFetchModel;
using NUnit.Framework;
using Xtensive.Core;

namespace Xtensive.Orm.Tests.Issues.IssueJira0793_FieldValidationTriggersLazyLoadFieldsFetchModel
{
[HierarchyRoot]
public class Book : Entity
{
[Field, Key]
public int Id { get; set; }

[Field(Length = 50), NotNullOrEmptyConstraint]
public string Title { get; set; }

[Field(Length = int.MaxValue, LazyLoad = true)]
public string Description { get; set; }

[Field(LazyLoad = true)]
public byte[] BookFile { get; set; }

[Field(Length = 5)]
public string FileExtension { get; set; }

[Field]
public Author Author { get; set; }
}

[HierarchyRoot]
public class Author : Entity
{
[Field, Key]
public int Id { get; set; }

[Field()]
public string FirstName { get; set; }

[Field]
public string LastName { get; set; }

[Field(Length = int.MaxValue, LazyLoad = true)]
[NotNullConstraint]// should always be triggered
public string Biography { get; set; }
}

[HierarchyRoot]
public class Chapter : Entity
{
[Field, Key]
public int Id { get; set; }

[Field]
public Book Owner { get; set; }

[Field]
public string Title { get; set; }

[Field(Length = int.MaxValue, LazyLoad = true)]
[NotNullOrEmptyConstraint(ValidateOnlyIfModified = true)]// should validate only if changed
public string Description { get; set; }
}

public class QueryCounter
{
public int Count { get; private set; }

public Disposable Attach(Session session)
{
session.Events.DbCommandExecuted += Encount;
return new Disposable((disposing) => session.Events.DbCommandExecuted -= Encount);
}

public void Reset() => Count = 0;

private void Encount(object sender, DbCommandEventArgs eventArgs) => Count++;

public QueryCounter()
{
Count = 0;
}
}
}

namespace Xtensive.Orm.Tests.Issues
{
public class IssueJira0793_FieldValidationTriggersLazyLoadFieldsFetch : AutoBuildTest
{
private Key oblomovKey;
private Key goncharovKey;

protected override DomainConfiguration BuildConfiguration()
{
var configuration = base.BuildConfiguration();
configuration.Types.Register(typeof(Book).Assembly, typeof(Book).Namespace);
configuration.UpgradeMode = DomainUpgradeMode.Recreate;
return configuration;
}

protected override void PopulateData()
{
using (var session = Domain.OpenSession())
using (var transaction = session.OpenTransaction()) {
var author = new Author() {
FirstName = "Ivan",
LastName = "Goncharov",
Biography = "Some biography of Ivan Alexandrovich" };
var book = new Book() {
Title = "Oblomov",
Description = "A drama about how human's lazyness and absence of strenght may affect his life.",
BookFile = new byte[] { 3, 3, 3, 3, 3, 3, 3 },
Author = author
};

new Chapter() { Title = "Chapter #1", Description = "Detailed description of Chapter #1", Owner = book };
new Chapter() { Title = "Chapter #2", Description = "Detailed description of Chapter #2", Owner = book };
new Chapter() { Title = "Chapter #3", Description = "Detailed description of Chapter #3", Owner = book };

oblomovKey = book.Key;
goncharovKey = author.Key;

transaction.Complete();
}
}

[Test]
public void LazyFieldHasNoConstraintTest()
{
var counter = new QueryCounter();
using (var session = Domain.OpenSession()) {
using (counter.Attach(session))
using (var transaction = session.OpenTransaction()) {
var oblomov = session.Query.Single<Book>(oblomovKey);
oblomov.Title = "Oblomov by Goncharov";
transaction.Complete();
}
Assert.That(counter.Count, Is.EqualTo(2));
counter.Reset();
}
}

[Test]
public void LazyFieldHasCheckAlwaysConstraintTest()
{
var counter = new QueryCounter();
using (var session = Domain.OpenSession()) {
using (counter.Attach(session))
using (var transaction = session.OpenTransaction()) {
var goncharov = session.Query.Single<Author>(goncharovKey);
goncharov.FirstName = goncharov.FirstName + "modified"; // should prefetch lazy load field
transaction.Complete();
}
Assert.That(counter.Count, Is.EqualTo(3));
counter.Reset();
}
}

[Test]
public void LazyFieldHasCheckIfModifiedConstraintTest()
{
var counter = new QueryCounter();
using (var session = Domain.OpenSession()) {
using (counter.Attach(session))
using (var transaction = session.OpenTransaction()) {
foreach (var chapter in session.Query.All<Chapter>()) {
chapter.Title = chapter.Title + " modified";
}
transaction.Complete();
}
Assert.That(counter.Count, Is.EqualTo(2));
counter.Reset();
}

using (var session = Domain.OpenSession()) {
int updatedItems = 0;
using (counter.Attach(session))
using (var transaction = session.OpenTransaction()) {
foreach(var chapter in session.Query.All<Chapter>()) {
chapter.Description = chapter.Description + " modified";
updatedItems++;
}
transaction.Complete();
}
Assert.That(counter.Count, Is.EqualTo(5)); // query + fetches + update
counter.Reset();
}
}
}
}
Binary file modified Orm/Xtensive.Orm.Tests/Model/UnicodeNamesTest.cs
Binary file not shown.
Loading