hi my name is noah gift and today we're going to cover how to test.net code inside of
the github actions ecosystem alongside github code spaces what's really cool about this is
i can click a button create a repo create a development environment that uses visual
studio code in the cloud go through test my code and then automatically get this to run
with github actions all right let's go ahead and get started
all right so we're going to get in here and build out a c-sharp
x-unit github actions continuous integration environment we're also going to do it inside
of github code spaces which is a cloud-based development environment
so to go ahead and get started here what i'm going to do is i'm going to create a new environment
and in this new environment here what will be nice is that i'll be able to start from zero
so go ahead and do this we'll go ahead and say demo c-sharp github code spaces
and what i'll be able to do here is say public add a readme what we'll do vs
visual studio here as our template perfect and go ahead and create this repo once i've created it
we're able to go to code and i'm going to select code space and i'm going to
go to this icon right here and i'm going to select configure and create code space
once i've done this i'll be able to select whatever size machine i want
because i'm compiling code i want a beefy machine i'm going to go ahead and select 16
core with 32 gigs of ram and 128 gigs of storage great let's go ahead and create this code space
uh now that i've got this thing uh what's really cool about it is i can use visual
studio code that the desktop type environment but inside of the cloud i'll go ahead and
go through here and configure the color theme i like to use the color theme here for
visual studio dark perfect got this thing working now that i've got this uh we're really ready to to
start installing things and so that the next step uh for me is i'm going to copy what i did earlier
here which is i'm going to make a directory and i'm going to cd into it then i'm going to run.net
new x unit so let's go ahead and first actually check the.net version so if we say dot net
version what do we got we are running.net 6 which is what i want that's great
um let's go ahead and now make a directory for our tests hello tess cd into it and then
use the net command to create a new x unit command here looks like we have too many steps here which
is fine i'll just go ahead and cd into hello tess and now go ahead and run dotnet new x unit
perfect so this goes through here and it creates our template for for net and it gives me this
directory right here with a starter kit for our for our code because i'm going to
do this as a demo i want to move quickly and what i can do is i can actually just grab
my example from what i did earlier and i'm going to go ahead and just paste it in here
and and this is a very simple example what it does is it not only builds out a test and you
can see here this is the way the test work fact is as as at the top of the public void passing test
and i say assert equal two and two and then inside i actually build the logic this is
not obviously not something you would do in a real world scenario but i'm just gonna add a
a method here that is able to add two integers together and return them and
then i'm going to assert that that's actually true and so once i've got this set up here
we're we're pretty close all we need to do is is actually run our code and how would i actually do
that well uh fortunately in my other project here i actually set up github actions and we'll do this
in a second and what's nice about github actions is that you can actually use it as a is it really
like a template to to understand how to run your project so here we go net test hello test no build
verbosity normal let's go ahead and run this oh it says what's happening here because i'm in this
directory i can just go up one level and now i can run that command and you can see here that in fact
it is a build failure because i believe we need to first create the dll and so
in order to do that pretty easy we would just go through here and we would just say
the the build command and and so we can again just follow our
our steps here we can say dot net restore hello test let's go ahead and do that
that goes through and it checks to see if there's any dependencies and installs them and then we go
ahead and we build our project uh our next step perfect that's gonna go ahead and create that dll
once that's done now we can run our our test command so this is really cool is that
once you start to build out a continuous integration workflow it actually should match
identically in this case it does match we see that there's a a past test right here so we've we got
the testing working locally here now the trick is how do we make the build system which is github
actions do it automatically and so i'm going to go ahead and show you how to do that so i'm going
to say git status and we see here's our directory full of our code let's go ahead and add that it's
nice that i don't have to do much because i have github integrated with ssh keys and all that stuff
already automatically because it's github code spaces adding test project i go ahead and push
this and now that i've got this pushed if i refresh you'll see that i've got all this inside
of here to use github actions i can go ahead and select this icon github actions and notice it'll
even give me suggestions like here we go build and test a net app etc etc what we can do and i do
think it's a good idea to explore those but we can just uh select create a work space for ourselves
and i'm going to go to my other project here where i had already done a lot of the hard work and i'm
going to paste this inside of this project there we go now let's go ahead and read what it says
we call this thing.net and what it's going to do is it's going to on every push and in fact let's
just leave this we just we just care about pushes let's go ahead and build the the main branch
it's going to run in ubuntu right so linux is going to actually test our c-sharp code
we're going to make sure that it's using.net 6 and then we're going to run three commands
first we're going to restore the dependencies dot net restore hello test we did that earlier
second we're going to build so net build hello test no restore and then we're going to go through
and run test and this will say net test hello test no build let's go ahead and commit this
and once it's committed if we go back here and we look at this it'll take a second here to to run
let's go ahead and double check here we go it's running we can actually watch the build in action
and this is what's really nice about this continuous integration environment
is i can i can toggle it and in real time make sure that everything works if i'm working with
a bunch of developers we can ensure that all of our code is is actually able to run
uh here we go here's step two restoring the dependencies building comes next once that's done
the testing goes next and of course things are able to pass perfect and now if i want to i can
add this status badge i can go to this menu here click status badge copy it then go back to the
readme and paste it in so as you can see very very straightforward to set up continuous integration
inside of github code spaces for c-sharp uh in fact i can just go back here do a git pull
and it pulls everything in i can run those same commands again dotnet test
we see everything works so a very great environment for doing uh continuous
integration with c-sharp is this github plus get up code spaces plus github actions workflow