public IObservable <TimeSpan> GetAppUsageTime(DateTime?start = null, DateTime?end = null) { var(startTicks, endTicks) = ToTickRange(start, end); var ticks = ExecuteScalar <long>(@"select sum( (case when au.EndTimestamp > @end then @end else au.EndTimestamp end) - (case when au.StartTimestamp < @start then @start else au.StartTimestamp end)) from AppUsage au where StartTimestamp <= @end and EndTimestamp >= @start", ("start", startTicks), ("end", endTicks)); return(Observable.Return(TimeSpan.FromTicks(ticks))); }
public void GetPhoneNumber_ThrowException_Verify() { // Arrange ShimSqlCommand.Constructor = _ => { new ShimSqlCommand(_) { InstanceBehavior = ShimBehaviors.Fallthrough, ExecuteScalar = () => { ExecuteScalar = true; Disposed++; throw new InvalidOperationException("something wrong"); } }; }; // Act Action = () => Instance.GetPhoneNumber(); // Assert Action.ShouldThrow <InvalidOperationException>().Message.ShouldBe("something wrong"); this.ShouldSatisfyAllConditions( () => ExecuteScalar.ShouldBeTrue(), () => ConnectionOpen.ShouldBeTrue(), () => Disposed.ShouldBe(1)); }
public void GetPhoneNumber_WhenCalledWithVoidMethod_Verify() { // Arrange, Act Instance.GetPhoneNumber(); // Assert this.ShouldSatisfyAllConditions( () => Records.Count.ShouldBe(15), () => Instance.Id.ShouldHaveSingleItem()); this.ShouldSatisfyAllConditions( () => Records.ShouldContain(Tuple.Create("Area", "0121", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Area", "0122", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Area", "0123", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Area", "0124", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3455", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3456", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3457", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3458", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3459", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "34510", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "34511", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "345", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Minor", "6789", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("ToString", "(012)345-6789--Area: 012Major: 345MinorMinor: 6789", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("FizzBuzz", "FizzBuzz", DbType.String, (Object)null)), () => ConnectionClosed.ShouldBeTrue(), () => ExecuteScalar.ShouldBeTrue(), () => ConnectionOpen.ShouldBeTrue(), () => Disposed.ShouldBe(1), () => Instance.Id.ShouldContain(1)); }
public static Team Create(string name, int leagueId) { using var transaction = BeginTransaction(); var count = ExecuteScalar <long>("SELECT COUNT(*) FROM teams WHERE name=@name AND league_id=@leagueId", ("name", name), ("leagueId", leagueId)); if (count != 0) { transaction.Rollback(); throw new DuplicateNameException($"Duplicate team {name} in league {leagueId}."); } var id = ExecuteScalar <long>( "INSERT INTO teams (name, league_id) VALUES (@name, @leagueId); SELECT last_insert_rowid()", ("name", name), ("leagueId", leagueId)); transaction.Commit(); return(new Team(id, name, leagueId)); }
public void GetPhoneNumber_WhenCalled_Verify(bool voidMethod) { // Arrange, Act if (voidMethod) { Instance.GetPhoneNumber(); } else { Instance.SavePhoneNumber(); } // Assert this.ShouldSatisfyAllConditions( () => Instance.Id.ShouldHaveSingleItem(), () => Records.Count.ShouldBeGreaterThanOrEqualTo(2)); if (CheckParameter("True")) { Records.Count.ShouldBe(15); this.ShouldSatisfyAllConditions( () => Records.ShouldContain(Tuple.Create("Area", "0121", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Area", "0122", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Area", "0123", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Area", "0124", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3455", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3456", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3457", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3458", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "3459", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "34510", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "34511", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Major", "345", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("Minor", "6789", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("ToString", "(012)345-6789--Area: 012Major: 345MinorMinor: 6789", DbType.String, (Object)null)), () => Records.ShouldContain(Tuple.Create("FizzBuzz", "FizzBuzz", DbType.String, (Object)null)), () => ConnectionClosed.ShouldBeTrue(), () => ExecuteScalar.ShouldBeTrue(), () => ConnectionOpen.ShouldBeTrue(), () => Disposed.ShouldBe(1), () => Instance.Id.ShouldContain(1)); } if (CheckParameter("False")) { this.ShouldSatisfyAllConditions( () => ShouldContain(Records, "Parameter1", "", DbType.String, (string)null), () => ShouldContain(Records, "FizzBuzz", "FizzBuzz", DbType.String, (string)null), () => Instance.Id.ShouldContain(111)); } }
public bool DoesAppHaveTag(App app, Tag tag) { return(null != ExecuteScalar <long?>("select AppId from AppTag where AppId=@app and TagId=@tag", ("app", app.Id), ("tag", tag.Id))); }